Reputation: 123
I made an android application. I run application on laptop and located me at one place(in a wrong town about 250 km). When run application on my desktop with another api key, located me on the same wrong city. Can anyone tell me where is the problem? Thank you!
Upvotes: 0
Views: 5601
Reputation: 10365
In my experience, Android won't acquire a location just because your Wi-Fi will inherit that to the Emulator.
You need to follow some steps:
Be sure to have the following permissions in your Android Manifest:
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_MOCK_LOCATION
android.permission.CHANGE_WIFI_STATE
android.permission.ACCESS_WIFI_STATE
Be sure to have the maps library in your Application tag:
<application android:icon="@drawable/ic_launcher" >
<uses-library android:name="com.google.android.maps" />
</application>
Be sure to have a valid Maps API Key in your MapView in your /layout/map.xml file.
Because you are not running your App on an actual device, the only way to send different locations to your App is to push a MOCK LOCATION. To do so, simply Launch your App in the Emulator, go to the DDMS perspective in Eclipse IDE, and look for the options on the left (reset the DDMS perspective if you can't find them). It should look like this:
Select the Emulator Name under the "Devices" Tab, then you can send Latitude and Longitude coordinates using the "Location Controls".
When you are done developing and testing, be sure to remove the ACCESS_MOCK_LOCATION permission and to test the location detection on an actual phone or tablet with either GPS, aGPS chip or Cellular/Wifi Network.
Upvotes: 1
Reputation: 18018
When you run a mobile application on desktop simulator, which doesn't have GPS in it, you will get some fixed location every time. To get real GPS coordinates you need to install it in a android device and test it.
** Update **
If you are having the same problem on your phone too, then your phone GPS is probably switched off, which you need to turn on, or phone is using Wifi to get a fix on its location.
Upvotes: 1
Reputation: 3544
Just a thought, is the phone getting the GPS location through your home wifi network rather than the phone's GPS? Might explain why they both give the same wrong value.
Upvotes: 0