2016-06-25 11 views
0

Ich bin mit einem seltsamen Problem konfrontiert. Ich habe den von google bereitgestellten offiziellen Mock-Provider-Quellcode modifiziert, um eine Route für meine Anwendung nachzuahmen.Location Mocking - Google Map erkennt die Bewegung, aber meine eigene Anwendung löst keine Standortänderung

Verwenden Sie diesen Code.

mockLocation.setElapsedRealtimeNanos(elapsedTimeNanos); 
         mockLocation.setTime(currentTime); 

         // Set the location accuracy, latitude, and longitude 
         mockLocation.setAccuracy(mLocationList.get(index).getAccuracy()); 
         mockLocation.setLatitude(mLocationList.get(index).getLatitude()); 
         mockLocation.setLongitude(mLocationList.get(index).getLongitude()); 
         mockLocation.setSpeed(mLocationList.get(index).getGpsSpeed()); 
         mockLocation.setBearing(80); 
         mockLocation.setAltitude(mLocationList.get(index).getAltitude()); 



         // Inject the test location into Location Services 
         LocationServices.FusedLocationApi.setMockLocation(mLocationClient,mockLocation); 

Google Karte erkennt diese Bewegung aber meine Anwendung ist nicht Standort-Updates bekommen

irgendeine Idee?

Antwort

0

Schlingen Sie diesen ganzen Prozess nicht, etwas wie unten?

private void startSpoofing(){ 
    LocationServices.FusedLocationApi.setMockMode(mGoogleApiClient, true); 
    while (mRunning) { 
     LocationServices.FusedLocationApi.setMockLocation(mGoogleApiClient, l); 
     l.setTime(System.currentTimeMillis()); 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 
      l.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); 
     } 

     try { 
      Thread.sleep(TIME_BETWEEN_UPDATES_MS); 
     } catch (Exception e) {} 
    } 
} 

Wenn Sie Schleife dies wird OnLocationChanged Verfahren ausgelöst werden