Reputation: 33
I am using Location Manager
for getting the current longitude and latitude, but in an emulator I am getting an error. How do I get locations on emulator?
This is my code:
lm = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
android.location.Location currentLocation = lm
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (currentLocation == null)
currentLocation = lm
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (currentLocation != null) {
currentLongitude = currentLocation.getLongitude();
currentLatitude = currentLocation.getLatitude();
// Get last location of driver
lastLongitude = Double.valueOf(app.GetLongitude(context));
lastLatitude = Double.valueOf(app.GetLatitude(context));
distance = CommonFunctions.GetDistance(currentLongitude,
currentLatitude, lastLongitude, lastLatitude);
}
Upvotes: 3
Views: 777
Reputation: 163
First you must open emulator control view (Window->showView-> other->emulator control). Then when your application start, at location control in emulator control, set a location and click send button
Upvotes: 0
Reputation: 5378
You'll find this window in the DDMS perspective in Eclipse. This way you can test your application with various location values.
Follow below steps to set mock values:
go to eclipse DDMS perspective,Via
Windows>Open Perspective > other > DDMS (You can type to filter the list)
find Emulator Control tab
then inside Location Control box
You can send lat, long to emulator to simulate gps changes.
if you cannot find Emulator Control, just open it via:
Windows > show view > other > Emulator Control (You can type to filter the list)
Upvotes: 3
Reputation: 5183
For a very explained answer you may check here: How to emulate GPS location in the Android Emulator?
In this post it explains how you can deal with problem!
Hope this helps!
Upvotes: 0
Reputation: 1411
Open your Emulator control in Eclipse and set lat,long in Location controls
Upvotes: 0