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
1
Question by yzeal · Jun 08, 2014 at 06:17 PM · androidgpsoffline

How can I get GPS data on my Android device without WiFi?

Is there any way to get location data (GPS) on Android reliably when the device is offline without writing a plugin by now?

I'm referring to this plugin tutorial: http://www.mat-d.com/site/unity-gps-plugin-development-tutorial-building-a-android-plugin-for-unity-with-eclipse-and-ant/

I'm using this method right now with Unity 4.5: http://docs.unity3d.com/ScriptReference/LocationService.Start.html

I don't get any information when I'm offline (longitude and latitude 0.0) on my Asus tablet (Android 4.2.2). When I'm online I do get data, but with pretty low accuracy (~ 40m), even outside.

Running the same app with my Samsung Galaxy S3 (Android 4.3), I don't experience any problems, with or without WiFi. I get extremely accurate results (~ 3-5m; outdoors, of course).

Is this dependant on the device or the Android version? Does anyone have any idea?

If there's no other way I'll try to get the plugin working. (Sorry, I'm new to all of this and a bit intimidated by the whole plugin building process.)

EDIT: Solved! =D Kind of. See my answer for my solution.

Comment
Add comment · Show 2
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 tanoshimi · Jun 08, 2014 at 06:31 PM 0
Share

And your Asus tablet has GPS? Without meaning to state the obvious, but if it doesn't have a GPS chip and you turn off the Wi-Fi, I'm not sure how else you'd expect it to report location.

avatar image yzeal · Jun 08, 2014 at 07:18 PM 0
Share

It does have GPS, and I've tried turning it on manually with the same results. I seem to get the data just fine using apps from the Google Play Store.

A friend of $$anonymous$$e has the same problem when she runs my app on her Phone.

(But I see why you had to ask. =) )

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by yzeal · Jun 10, 2014 at 08:19 PM

In the end, I basically just followed http://www.mat-d.com/site/unity-gps-plugin-development-tutorial-building-a-android-plugin-for-unity-with-eclipse-and-ant/ but I thought I'd post it anyway, because I had some (n00b) trouble with it.

The good news: There is indeed a way to get GPS data without WiFi or mobile network connections. The bad news: I did have to write a Unity plugin. But as soon as the GPS is activated by the plugin, Unity's methods also start working properly.

Because I also use Vuforia for my AR app, I had some trouble with the plugin tutorial mentioned above. In case anyone is trying to do something similar, the solution is pretty simple but took me an embarrassing amount of time to figure out:

You can use the GPSTest.java code from the tutorial (I added some code to return latitude and logitude), but you need to add the following to the imports:

 import com.qualcomm.QCARUnityPlayer.QCARPlayerNativeActivity;

And your class needs to extend QCARPlayerNativeActivity instead of UnityPlayerActivity

 public class GPSTest extends QCARPlayerNativeActivity {

as described here: https://developer.vuforia.com/resources/dev-guide/unity-android-plugins

Follow the steps in the Vuforia tutorial, but use the altered GPSTest.java, and that's it!

In my code, I use the plugin just for testing like this (as described in the tutorials) for example:

 using UnityEngine;
 using System.Collections;
 
 public class GPSTestSkript : MonoBehaviour {
 
     public string speed;
     public double latitude;
     public double longitude;
     
     private AndroidJavaObject jo;
 
     private bool posted;
 
     void Start () {
 
         #if UNITY_ANDROID  && !UNITY_EDITOR
             AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
             jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
         #endif            
     }
     
     void Update() {
         if(jo != null){
             latitude = jo.CallStatic<double>("getLatitude");
             longitude = jo.CallStatic<double>("getLongitude");
             speed = jo.CallStatic<string>("getSpeed");
         }
     }
 }
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 zharik86 · Jun 11, 2014 at 06:44 AM 0
Share

As always. Unity normally works with the android if to write own plug-ins. It is sad:)

avatar image yzeal · Jun 11, 2014 at 01:13 PM 0
Share

True. At least I learned how to write Android plugins for Unity now. =) I'm sure it will work fine in Unity 5 or something.

avatar image
1

Answer by VonTala · Jan 07, 2016 at 11:14 AM

The answer is in the configuration of your android: settings -> location services (More) disable USE WIRELESS NETWORKS enable USE GPS SATELLITES after that my program start working with true lat - long

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 zharik86 · Jun 08, 2014 at 07:24 PM

You can receive your location two methods. The first method is to use the Unity method. But for this purpose to be necessary connection from the Internet. (GPS works with Wi-Fi or other Internet conection: 3G, 4G and etc). Or the second method which is specified at you in the reference is an approximate calculation of your coordinates on the basis of a mobile network.

Comment
Add comment · Show 8 · 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 yzeal · Jun 08, 2014 at 08:19 PM 0
Share

But why does it work on my S3 when I'm offline (and not on my friend's phone)? I don't really understand...

avatar image zharik86 · Jun 09, 2014 at 08:54 AM 0
Share

@yzeal Strange. I tested a code from Unity docs for GPS of coordinates on many devices of android (HTC and Sony and Sony Experia Tablet Z, and platform 2.2 - 4.2.2). If I in an offline, values were 0. As soon as it was connected to the Internet, I received coordinates. Unfortunately I have no S3 so couldn't check on it. $$anonymous$$aybe it depends on S3 (from its logic). Try to receive your coordinates when you are an offline and the mobile network is disconnected($$anonymous$$ode in the airplane). If it and after that will give out the correct coordinates, I buy S3 :)

avatar image yzeal · Jun 09, 2014 at 06:12 PM 0
Share

@zharik86 Thanks for taking so much time to help me! I just tried what you suggested, and I guess you're getting a new phone. ;) Indoors, it just gave me the values from the last connection and stopped updating (as can be expected, because it was using the WiFi connection), but as soon as I went outside and waited for a bit, it gave me values with very nice accuracy and ~ the update frequency I specified in Start() when I walked around.

I still don't get why the device would need a WiFi connection to turn on its GPS chip. $$anonymous$$y navigation system certainly isn't capable of going online or connecting to a mobile network. But I have to admit that I don't understand very much about that kind of technology, so I'm probably getting something really wrong.

avatar image zharik86 · Jun 09, 2014 at 07:49 PM 0
Share

@yzeal Really, in I created the project in the last Unity(4.5). I set it on Sony Experia Tablet Z (android 4.4.2). I delivered in pad settings: Location-> only GPS. And without Wi-Fi I received any coordinates excellent from 0. In Unity 4.1.2 which I use, Wi-Fi was in most cases necessary. Try to change Location Settings on other device. And the main thing, different Android versions work on a different with GPS.

And when I created applications for location deter$$anonymous$$ation, I had to test them to the Android 4.2.2 version. So there is nothing surprising that for this version the android and is necessary to Wi-fi.

avatar image zharik86 · Jun 10, 2014 at 06:17 AM 0
Share

@yzeal Have you correct coordinates of GPS(offline mode)? Simply latitude at me correct, but here longitude incorrect. It turns out that longitudeTRUE = longitudeGPS - latitudeGPS. It is strange. There can be the next bug the android 4.4.2.

Show more comments

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

24 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

Related Questions

Is it possible to get real world coordinates and use it to trigger event in game? 1 Answer

Multiplayer on Android? 0 Answers

Unity3D Android NullReferenceException for class properties during using Input.location.lastData 2 Answers

Get Real GPS not WiFi GPS 2 Answers

Why I can't get GPS information on Android device 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