• 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 /
This question was closed Jul 22, 2015 at 01:00 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ewan Blackburn · Mar 12, 2013 at 04:38 PM · androidgpstabletunity android

GPS Application with Unity Android

Hi all, I've managed to create a tablet app that uses GPS to set the location of a camera object. I know the tablet is communicating with the unity application because it manages to receive the magnetic compass data and is being displayed as an integer on a GUI interface. My issue is that i cannot seem to get the GPS module to communicate with the unity android application i have made. All code i could find online seems to use outdated functions for unity 4.0 and i was wondering if unity android can even access the GPS module?

variables

 /* GPS Variables */
 var lat : float = 0;        //lattitude , longitude and altitude variables
 var lon : float = 0;
 var alt : float = 0;
 var accuracy : int =10;    //accuracy of the GPS module in m
 var distance : int = 10;    // minimum distance before next location variables allocation
 var maxWait : int = 20;    //maximum time (s) before time out
 var locationStatus : int =0;        
     

start function

 function Start () 
 {
     Input.location.Start();                    //enable location settings
     Input.compass.enabled = true;
     locationStatus = LocationServiceStatus.Stopped;
 
     startLocationService();                     //begin GPS transmittion
 }

 
 function Update () 
 {
    if(locationStatus == LocationServiceStatus.Running)
     {
         
         lat = Input.location.lastData.latitude;
         lon = Input.location.lastData.longitude;
         alt = Input.location.lastData.altitude;
         
         //print(lat);
         //print(lon);
         //print(alt);

 GUI.Box(Rect(Screen.width - 200,Screen.height - 50, 100,50), "Latitude => " +lat + "\n Longitude => " + lon + "\n Altitude => "  +alt );
        
     } 
 }
 
 
 function startLocationService()
 {
     Input.location.Start(accuracy, distance);
     
 
     while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) 
     {
         WaitForSeconds(1);
         maxWait--;
        locationStatus = Input.location.status;
     }
 } 



The following code all compiles and runs on the android device but the lat lon and alt values stay as 0

Any suggestions would be great as I'm currently tearing my hair apart at this one!

Ewan

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by imnimn · Sep 16, 2013 at 07:32 PM

Hi Ewan, the problem is that you use locationStatus of type int. And here is the problem I've tried to put Input.location.status instead of it and it is worked well . and changed after almost ten meters. also there is yield should be before wait for seconds

I wish that it be benefit to you and really thank you because it was benefit to me.

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Unity Android Inputs With Samsung Galaxy Ace 0 Answers

Android Tablet GPS not working 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to make a menu like ironpants 0 Answers

Reloading the scene causes ads to reload. Is this ok ? 3 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