Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to import GPS location coordinates from Android device?

Discussion in 'Android' started by jsr2k1, Dec 5, 2010.

  1. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    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
     
  2. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    The GPS location info is currently not supported on Android.
     
  3. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Ok, thanks for the response.

    So, can I get GPS location info with a plugin using the NDK (or SDK) libraries from Android SDK?

    Joel
     
  4. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Yes, by using the Java LocationManager interface (Android Dev Guide: Obtaining User Location) and a thin native wrapper between C# and Java, it shouldn't be too hard. But we will of course add this property, most probably in the very next release.
     
  5. Xandrilios

    Xandrilios

    Joined:
    Apr 13, 2010
    Posts:
    3
    Hi,

    We have been trying to create a plugin + bridge to read GPS Location at school.
    We have run into a problem which is the following:

    Using Unity 3.1.0f4, we cannot get Java plugins to work.

    On Unity 3.0, we can run the (self-built using cygwin) example Java Plugin project, but get the following error in 3.1:
    "Unable to find javabridge" (where javabridge is the name of our DLL, as used in the example, libjavabridge.so)

    This problem occurs only on 3.1.0 for the Example project and for both 3.0 and 3.1 for our own created GPS Plugin.

    Is this a known problem in the recent version of Unity and/or might there be a common mistake we are making? Like: would this error occur when we have a faulty C++ bridge?


    This problem would of course be solved if we can use GPS directly in Unity, so please do your best!
     
  6. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Did you account for the (3.1) re-arrangement in the Unity Plugin directory layout to put Android plugins under Assets/Plugins/Android (ie not only Assets/Plugins/)?
     
  7. Xandrilios

    Xandrilios

    Joined:
    Apr 13, 2010
    Posts:
    3
    I did not, will try it now. Thank you!
     
  8. Xandrilios

    Xandrilios

    Joined:
    Apr 13, 2010
    Posts:
    3
    Ok, I now screwed up my SDK install, will need to try at a later stage, sorry and thanks again.
     
  9. mikriloulou

    mikriloulou

    Joined:
    Nov 30, 2010
    Posts:
    7
    Does anybody managed to obtain the GPS Location from Android already? If yes, could you please post some instructions on how to do this?
     
  10. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    GPS is supported in Unity 3.2 which is in alpha/beta state currently. But if you cant wait then the Android Developer Guide explains it in detail.
     
  11. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    25
    Hi!

    I successfully implemented an GPS plugin for a client of mine, which in turn asked if anyone would be willing to buy it here for about 100$.
    I can't decide to give it away for free, I'm sorry.
     
  12. krillmcrawl

    krillmcrawl

    Joined:
    Feb 18, 2011
    Posts:
    29
    From release notes in Android section for 3.2:
    "Implemented Location Service (GPS/Wifi)."

    Lots of questions:)

    Have anyone tried the GPS functions in 3.2? I guess it now should work with LocationInfo? Does it work with compass as well? Any js examples on how to work with it? This might open up for some layar type features!
     
  13. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
  14. dragon'78

    dragon'78

    Joined:
    Nov 7, 2011
    Posts:
    1
  15. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,080
    Does anyone know if LocationInfo or GPS/WiFiGPS works on Android yet? I've been getting 0's through this very simple guitxt update (both with loc reference declared in Update, and currently in Start)

    <code>
    var gtxt:GUIText;

    var loc:LocationInfo;

    function Start(){
    loc = new LocationInfo();
    }

    function Update () {

    //Debug.Log(loc.longitude);
    gtxt.text = displayLoc(loc.longitude, loc.latitude, loc.altitude, loc.horizontalAccuracy, loc.verticalAccuracy);
    }

    function displayLoc(lon:float,lat:float,alt:float,ha:float,va:float){
    return lon.ToString()+", "+lat.ToString()+" @ "+alt.ToString()+" | "+ha.ToString()+" "+va.ToString();
    }
    </code>
     
  16. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,080
    It's a bit misleading that the only way to start location update is to call iPhoneSettings.StartLocationServiceUpdates(); ... even on the Android.