Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Tamlou · Oct 28, 2020 at 01:00 PM · androidmaplocationgpspermissions

Ask for Location permission at the start of the App

I am using Mapbox which shows the Users location on a Map. When I open the scene on an Android device (Samsung S8) it requests the permission but when you press Allow, it loads a grey screen. The rest of the assets are there (GUI) but it looks like the Map hasn't initialized. if I close the App and reopen it, the Map now works. Testing it on iOS, it all works fine.

I thought that if I could get the permission to come up when you first open the App - as opposed to when you open the Map scene - that it would have time for the Map to initialize.

Does anyone know how I can solve this issue?

I have this script on the Camera in the Map scene:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Locating : MonoBehaviour
 {
     private Vector2 targetCoordinates;
     private Vector2 deviceCoordinates;
     public static float lat;
     public static float longi;
     private bool ready = false;
 
     private void Start(){
         StartCoroutine(StartLocationService());
         StartCoroutine(updateGPS());
     }
     public IEnumerator StartLocationService(){
         if (!Input.location.isEnabledByUser){
             Debug.Log("User has not enabled GPS");
             yield break;
         }
         Input.location.Start();
         int maxWait = 20;
         while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0){
             yield return new WaitForSeconds(1);
             maxWait--;
         }
         if (maxWait < 1){
             Debug.Log("Timed out");
             yield break;
         }
 
         if (Input.location.status == LocationServiceStatus.Failed){
             Debug.Log("Unable to determine device location");
             yield break;
         }
         else{
             longi = Input.location.lastData.longitude;
             lat = Input.location.lastData.latitude;
         }
         ready = true;
     }
     public IEnumerator updateGPS(){
         if (!Input.location.isEnabledByUser){
             Debug.Log("User has not enabled GPS");
             yield break;
         }
         float UPDATE_TIME = 1f;
         WaitForSeconds updateTime = new WaitForSeconds(UPDATE_TIME);
         while (true){
             /* mapScript.Refresh();*/
             longi = Input.location.lastData.longitude;
             lat = Input.location.lastData.latitude;
             SetLocation();
             yield return updateTime;
         }
     }
     void SetLocation(){
         // radius.transform.position = new Vector3(0, 0, 6);
     }
 }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cubixrube · Apr 15, 2021 at 02:14 AM 0
Share

@Tamlou did you find a solution to this? I'm running into the same issue. Menu scene > Mapbox map. Map is blank and grey, restart app and map pops up just fine. Thanks in advance.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Oct 28, 2020 at 01:43 PM

If you add the ACCESS_FINE_LOCATION permision to the AndroidManifest.xml it should ask request the permision at the start of the app if i am not wrong.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tamlou · Oct 28, 2020 at 01:54 PM 0
Share

Hi, Thanks for the reply. $$anonymous$$y Android $$anonymous$$anifest includes both ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION It's also worth mentioning that I have a 'Home' scene, then the scene with the $$anonymous$$ap is an AssetBundle - this is when it asks for permission for location. I don't know if it being an AssetBundle affects when the permission is asked

avatar image
0

Answer by Cubixrube · Apr 15, 2021 at 05:42 AM

I seem to have found a solution here: https://docs.unity3d.com/Manual/android-RequestingPermissions.html Grabbed the code and changed all cases of "Permission.Microphone" to "Permission.FineLocation". It now asks for permission in my menu scene which allows Mapbox to load the map properly when you go to the map scene. Tested on several galaxy and pixel devices.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

301 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get Android devices current country location 0 Answers

GPS Locate.permission Android? 0 Answers

GPS doesn't work in AGPS mode 0 Answers

How to import GPS location coordinates from Android device? 4 Answers

Location Service on iOS 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges