Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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
0
Question by hollym16 · Jul 14, 2017 at 02:31 PM · iosxcodemaplocationgps

Location Service on iOS

I'm building an App that displays a Google Static Maps of where the user is located. I've built on Android and it all works as expected, however, on iOS the latitude and longitude values don't change and the Google Static Map doesn't display.

The error I get when running in Xcode is:

Location service updates are not enabled. Check LocationService.status before querying last location.

In Xcode I have added all the Location related permission to the Info.plist and even added the MapKit.framework, but it doesn't fix the issue.

Has anyone else had this issue?

Here are my two scripts:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 public class GoogleMap : MonoBehaviour
 {
     public enum MapType
     {
         RoadMap,
         Satellite,
         Terrain,
         Hybrid
     }
     public bool loadOnStart = true;
     public bool autoLocateCenter = true;
     public GoogleMapLocation centerLocation;
     public int zoom = 13;
     public MapType mapType;
     public int size = 512;
     public bool doubleResolution = false;
     public GoogleMapMarker[] markers;
     public GoogleMapMarker[] endMarkers;
     public GoogleMapPath[] paths;
     public GameObject radiusMarker;
     public GameObject AugmentButton;
     public Text ProximityText;
 
     public float distanceFromTarget = 0.0003f;
     private float proximity;
     private Vector2 targetCoordinates;
     public float dLatitude = 52.236955f, dLongitude = -0.901292f;
 
     private float getLat;
     private float getLong;
 
     Vector2 RCurrentPos;
   
     void Start() {
         targetCoordinates = new Vector2(dLatitude, dLongitude);  
     }
 
     public void Refresh() {
         getLat = GPSscript.lat;
         getLong = GPSscript.longi;
 
         if (autoLocateCenter && (markers.Length == 0 && paths.Length == 0))
         {
             Debug.LogError("Auto Center will only work if paths or markers are used.");
         }
         StartCoroutine(_Refresh());
     }
     IEnumerator _Refresh()
     {
         var url = "https://maps.googleapis.com/maps/api/staticmap";
         var qs = "";
         if (!autoLocateCenter)
         {
             if (centerLocation.address != "")
                 qs += "center=" + WWW.UnEscapeURL(centerLocation.address);
             else
             {
                 qs += "center=" + WWW.UnEscapeURL(string.Format("{0},{1}", getLat.ToString(), getLong.ToString()));
             }
 
             qs += "&zoom=" + zoom.ToString();
         }
         qs += "&size=" + WWW.UnEscapeURL(string.Format("{0}x{0}", size));
         qs += "&scale=" + (doubleResolution ? "2" : "1");
         qs += "&maptype=" + mapType.ToString().ToLower();
         var usingSensor = false;
 #if UNITY_IPHONE
         usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;
         Debug.Log("iOS Stuff");
 #endif
         qs += "&sensor=" + (usingSensor ? "true" : "false");
         foreach (var i in markers)
         {
             qs += "&markers=" + string.Format("size:{0}|color:{1}|label:{2}", i.size.ToString().ToLower(), i.color, i.label);
             foreach (var loc in i.locations)
             {
                 if (loc.address != "")
                     qs += "|" + WWW.UnEscapeURL(loc.address);
                 else
                     qs += "|" + WWW.UnEscapeURL(string.Format("{0},{1}", getLat.ToString(), getLong.ToString()));
             }
         }
         foreach (var i in endMarkers)
         {
             qs += "&markers=" + string.Format("size:{0}|color:{1}|label:{2}", i.size.ToString().ToLower(), i.color, i.label);
             foreach (var loc in i.locations)
             {
                 if (loc.address != "")
                     qs += "|" + WWW.UnEscapeURL(loc.address);
                 else
                     qs += "|" + WWW.UnEscapeURL(string.Format("{0},{1}", loc.latitude, loc.longitude));
                 SetLocation(getLat, getLong);
             }
         }
         foreach (var i in paths)
         {
             qs += "&path=" + string.Format("weight:{0}|color:{1}", i.weight, i.color);
             if (i.fill) qs += "|fillcolor:" + i.fillColor;
             foreach (var loc in i.locations)
             {
                 if (loc.address != "")
                     qs += "|" + WWW.UnEscapeURL(loc.address);
                 else
                     qs += "|" + WWW.UnEscapeURL(string.Format("{0},{1}", loc.latitude, loc.longitude));
             }
         }
         var req = new WWW(url + "?" + qs);
         yield return req;
         GetComponent<Renderer>().material.mainTexture = req.texture;
     }
     void SetLocation(float latitude, float longitude)
     {
         RCurrentPos = new Vector2(latitude, longitude);
         proximity = Vector2.Distance(targetCoordinates, RCurrentPos);
         ProximityText.text = "Distance from destination: " + proximity;
         if (proximity <= distanceFromTarget)
         {
             AugmentButton.SetActive(true);
             radiusMarker.transform.position = new Vector3(0,1,6);
             Debug.Log("It worked");
         }else {
             AugmentButton.SetActive(false);
             radiusMarker.transform.position = new Vector3(0, -1, 6);
             Debug.Log("Didnt work");
         }
     }
     public enum GoogleMapColor
     {
         black,
         brown,
         green,
         purple,
         yellow,
         blue,
         gray,
         orange,
         red,
         white
     }
     [System.Serializable]
     public class GoogleMapLocation
     {
         public string address;
         public float latitude;
         public float longitude;
     }
     [System.Serializable]
     public class GoogleMapMarker
     {
         public enum GoogleMapMarkerSize
         {
             Tiny,
             Small,
             Mid
         }
         public GoogleMapMarkerSize size;
         public GoogleMapColor color;
         public string label;
         public GoogleMapLocation[] locations;
     }
     [System.Serializable]
     public class GoogleMapPath
     {
         public int weight = 5;
         public GoogleMapColor color;
         public bool fill = false;
         public GoogleMapColor fillColor;
         public GoogleMapLocation[] locations;
     }
 }

And this one:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GPSscript : MonoBehaviour
 {
     private Vector2 targetCoordinates;
     private Vector2 deviceCoordinates;
     public static float lat;
     public static float longi;
     public GoogleMap mapScript;
     public GameObject radius;  
     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()
     {
         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 unity_MPs-bafuUX1OKQ · Sep 29, 2020 at 12:49 PM 0
Share

Did you @hollym16 or anyone manage to get this script to work?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by seriyvolk83 · Jun 02, 2020 at 07:09 AM

Check status in updateGPS

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

94 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

Related Questions

Mapbox AR : Set map location in code 0 Answers

Need some advices for GPS on an android app 0 Answers

Radius around GPS location 1 Answer

Ask for Location permission at the start of the App 2 Answers

LocationService Delegate callback access 0 Answers


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