Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
2
Question by jsr2k1 · Dec 05, 2010 at 08:37 PM · androidlocationgpslocationinfo

How to import GPS location coordinates from Android device?

Hello, I tried to get latitude and longitude coordinates from 'Google Nexus One' and I failed.

I used the LocationInfo struct, but I think there is something missing. I wrote an Update function attached to 'GUI Text' like this:

void Update() { float lat, lon;

 LocationInfo li = new LocationInfo();

 lat = li.latitude;
 lon = li.longitude;

 guiText.text="LAT= "+ lat +"\nLON= " + lon;

}

Always returns 0.

Any idea? Thanks in advance,

Joel

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Joshua Falkner · May 31, 2011 at 11:31 PM

The answer to this is actually in the last place you'd expect. You have to first initialize the iPhoneSettings.StartLocationServiceUpdates() (Yes, I know you're on android. You have to use iPhoneSettings anyway) and then when the services is up and running update your loc variable with loc = iPhoneInput.lastLocation;

Read more about it here: http://unity3d.com/support/documentation/ScriptReference/iPhoneSettings.StartLocationServiceUpdates.html

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
avatar image
0

Answer by Maarten · Dec 05, 2010 at 08:42 PM

You are just creating an new LocationInfo object, which will always return 0. You should call a function to retrieve the values from your device.

I do not know which function you should call to retrieve them.

Comment
Add comment · Show 2 · 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 jsr2k1 · Dec 05, 2010 at 08:48 PM 0
Share

And that function is from unity libraries or android sdk?

Anyone has tested GPS with Android?

avatar image Maarten · Dec 05, 2010 at 08:58 PM 0
Share

I think you have to use the functions in the Android SD$$anonymous$$, and using a Plugin for Unity to be able to use them.

For more information on plugins, please see the url below: http://unity3d.com/support/documentation/$$anonymous$$anual/Plugins.html#AndroidPlugins

avatar image
0

Answer by MESSAOUDI · Jul 19, 2013 at 09:59 AM

Hello everyone, this is surely easy to arrange as a problem, which aims to use using methods use "location" for Unity 3D?

Thank you

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
avatar image
0

Answer by Imenbm · Mar 17, 2017 at 04:15 PM

you have to add this :

void Start()

 {
     Input.location.Start();
 }


void update()

{

StartCoroutine(UpdateLocation()) ; }

IEnumerator UpdateLocation() { Input.location.Start();

     // Wait until service initializes
     int maxWait = 20;
     while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
     {
         yield return new WaitForSeconds(1);
         maxWait--;
     }

     // Service didn't initialize in 20 seconds
     if (maxWait < 1)
     {
         Text singleText = mytext1.GetComponentInChildren<Text>();
         singleText.text = "Timed out";

     }
     // Connection has failed
     if (Input.location.status == LocationServiceStatus.Failed)
     {
         Text singleText = mytext1.GetComponentInChildren<Text>();
         singleText.text = "Unable to determine device location";

     }
     else
     {
         float lat = Input.location.lastData.latitude;
         float lon = Input.location.lastData.longitude;

}}

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Get Android devices current country location 0 Answers

How to pass accurate GPS location from android studio to unity? 0 Answers

Reverse Geolocation not returning correct country name 0 Answers

Location (Geographic boundary) Triggered Push Notifications in Android 0 Answers

Location Service not starting (Android) 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