Android examples for Map:Location
publish Mock Location
//package com.java2s; import android.app.Service; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.util.Log; public class Main { public static final String TAG = "DSN Debug"; public static final String PROVIDER_NAME = "testProvider"; public static void publishMockLocation(double latitude, double longitude, Context ctx, LocationListener listener) { LocationManager manager = (LocationManager) ctx .getSystemService(Service.LOCATION_SERVICE); publishMockLocation(latitude, longitude, ctx, manager, listener, PROVIDER_NAME);/*ww w.j a v a 2 s .c o m*/ } public static void publishMockLocation(double latitude, double longitude, Context ctx, LocationManager manager, LocationListener listener, String provider) { Location newLocation = new Location(provider); newLocation.setLatitude(latitude); newLocation.setLongitude(longitude); newLocation.setTime(System.currentTimeMillis()); newLocation.setAccuracy(25); manager.requestLocationUpdates(provider, 0, 0, listener); manager.setTestProviderLocation(provider, newLocation); Log.w(TAG, "published location: " + newLocation); Log.w(TAG, "LastKnownLocation of " + provider + " is: " + manager.getLastKnownLocation(provider)); } }