Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Craig S · Sep 26, 2012 at 01:44 AM · iphonegps

input.location not updating on Iphone

I'm building a simple location based game using GPS. I used some example code, but it seems the GPS is not updating after the finding the initial position. It only updates if i swap apps or something. For our game I need it to update every few seconds. I tried putting the "input.location" in the Update class, but got the same results. I'm using an Iphone 4 with IOS 5.1 and unity 3.5.5

Here is roughly the code i'm using:

 using UnityEngine;
 using System.Collections;
 
 public class question : MonoBehaviour {
     
     public float mylat;
     public float mylong;
     
     public float posScale = 1;
     public Vector2 globalPos;
     bool gpsRunning = false;
     public float gpsAccuracy = 100;
     public float gpsUpdateDistance = 10;    
     private bool ready = false;
     public TextMesh coordText;
     
     Vector2 MDMloc =  new Vector2(49.267356f,-123.090309f);
     
     // Use this for initialization
     void Start () {
         globalPos = new Vector2(MDMloc.y,MDMloc.x);
         StartGPS();
     }
     
     // Update is called once per frame
     void Update () {
             
     //    globalPos.x = Input.location.lastData.latitude;
     //    globalPos.y = Input.location.lastData.longitude; 
         
         mylat = (globalPos.x % 1) * 1000;
         mylong = (globalPos.y % 1) * 1000;
         transform.position = new Vector3(mylat*posScale, mylong*posScale, transform.position.z);
         coordText.text = "iphone gps: (" + globalPos.x + "," + globalPos.y + ")";
         coordText.renderer.material.color = new Color(1,0,0);
         
     }
     
     IEnumerator ActivateGPS() {
         gpsRunning = true;
         Input.location.Start(gpsAccuracy, gpsUpdateDistance);
         if (Input.location.status == LocationServiceStatus.Running)
             Debug.Log("**** LocationService Running");    
         
         float duration = 0;
         while (duration < 20.0f) {
              
             if (Input.location.status == LocationServiceStatus.Running
                 || Input.location.status == LocationServiceStatus.Failed) break;
             yield return new WaitForSeconds(0.1f);
 
             duration += 0.1f;
         }
             
         if (duration >= 20.0f) {
             Debug.Log("**** LocationService Timed out");    
         }
         
         if (Input.location.status == LocationServiceStatus.Failed) {
             Debug.Log("**** User declined LocationService?");
             gpsRunning = false;
         }
                 
         while (Input.location.status == LocationServiceStatus.Running) {            
             globalPos.y = Input.location.lastData.latitude;
             globalPos.x = Input.location.lastData.longitude; 
             
             yield return new WaitForSeconds(2.0f);
         }
         
     }
     
     public void StartGPS() {
         if (Application.isEditor) {
             return;
         }
         
         if (!gpsRunning) StartCoroutine(ActivateGPS());    
     }
 
     
     public void StopGPS() {
         Input.location.Stop();
         gpsRunning = false;
     }    
 
     void OnApplicationQuit() {
         StopAllCoroutines();
         Input.location.Stop();
     }
 
 }
 
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 rippenschneider · Apr 06, 2013 at 07:06 AM 0
Share

I am having the exact same problem. The postion only update very infrequent even if I move more than 100m?

Did you find a solution to this?

Regards Jens

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

Proximity iPhones alert 2 Answers

GPS on iPhone 6 giving me fits, will not Initialize and never asks me to enable 1 Answer

Input.location.start always times out 1 Answer

GPS location string 0 Answers

How to get GPS lattitude and longitude values ? 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