I have an Android app in which I need a user to make fun of my current location. Below is the code that I use so that the user presses the green button to start mocking their location.
Below the code begins to falsify the location when you press the "green button".
greenButton.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.addTestProvider(LocationManager.GPS_PROVIDER, "requiresNetwork" == "", "requiresSatellite" == "", "requiresCell" == "", "hasMonetaryCost" == "", "supportsAltitude" == "", "supportsSpeed" == "", "supportsBearing" == "", Criteria.POWER_LOW, Criteria.ACCURACY_FINE); Location newLocation = new Location(LocationManager.GPS_PROVIDER); newLocation.setLatitude(fakeLocation.getLatitude()); newLocation.setLongitude(fakeLocation.getLongitude()); newLocation.setAccuracy(fakeLocation.getAccuracy()); newLocation.setTime(System.currentTimeMillis()); newLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); lm.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true); lm.setTestProviderStatus(LocationManager.GPS_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis()); lm.setTestProviderLocation(LocationManager.GPS_PROVIDER, newLocation); } });
When I put a marker on the map and press the green button. The place mockingly begins. This "fake location" becomes my current location.
But after 10-20 seconds, a mocking end. My "real location" becomes my current location. I have seen many examples on the Internet, and they use the same code that I use to mock a location. I do not know why this is happening with my application. Any help would be appreciated.
android google-maps location
Parth bhoiwala
source share