Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Google Navigation with Mock Location
    primarykey
    data
    text
    <p>I have set up a MockLocationListener for my android app, but I'm kind of confused about h9ow too use it with Google Navigation. I'm not sure how Google Navigation will be able to pick up the fake location. </p> <p>Here is my MockLocationProvider: </p> <pre><code>public class MockLocationProvider { String providerName; Context ctx; public MockLocationProvider(String name, Context ctx) { this.providerName = name; this.ctx = ctx; LocationManager lm = (LocationManager) ctx.getSystemService( Context.LOCATION_SERVICE); lm.addTestProvider(providerName, false, false, false, false, false, true, true, 0, 5); lm.setTestProviderEnabled(providerName, true); } public void pushLocation(double lat, double lon) { LocationManager lm = (LocationManager) ctx.getSystemService( Context.LOCATION_SERVICE); Location mockLocation = new Location(providerName); mockLocation.setLatitude(lat); mockLocation.setLongitude(lon); mockLocation.setAltitude(0); mockLocation.setTime(System.currentTimeMillis()); lm.setTestProviderLocation(providerName, mockLocation); } public void shutdown() { LocationManager lm = (LocationManager) ctx.getSystemService( Context.LOCATION_SERVICE); lm.removeTestProvider(providerName); } } </code></pre> <p>Here is my activity:</p> <pre><code>public class MainActivity extends Activity { MockLocationProvider mock; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mock = new MockLocationProvider(LocationManager.NETWORK_PROVIDER, this); //Set test location mock.pushLocation(-12.34, 23.45); LocationManager locMgr = (LocationManager) getSystemService(LOCATION_SERVICE); LocationListener lis = new LocationListener() { public void onLocationChanged(Location location) { //You will get the mock location } //... }; locMgr.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 1000, 1, lis); String dLat = "38.062419"; String dLong = "-99.173584"; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" +dLat+","+dLong)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } protected void onDestroy() { mock.shutdown(); super.onDestroy(); } } </code></pre> <p>I'm not sure that I am using the mock locations properly with Google Navigation. I would appreciate it if someone could tell me how to use Google Navigation along with Mock Listener.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload