pulkit12
pulkit12

Reputation: 33

Dynamic geo Location update in android emulator?

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

Answers (4)

Huseyin
Huseyin

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

Lokesh
Lokesh

Reputation: 5378

You'll find this window in the DDMS perspective in Eclipse. This way you can test your application with various location values.

enter image description here

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

Dimitris Makris
Dimitris Makris

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

J.D.
J.D.

Reputation: 1411

Open your Emulator control in Eclipse and set lat,long in Location controls

Upvotes: 0

Related Questions