6

मैं ऐसी सेवा बनाने की कोशिश कर रहा हूं जो प्रत्येक एक्स सेकंड और वाई दूरी के बाद स्थान अपडेट प्राप्त करे। मुझे एक्स सेक के बाद अपडेट प्राप्त होते हैं लेकिन वाई दूरी के बाद कभी नहीं। मैंने इसे विभिन्न मानों के साथ कई बार परीक्षण किया है और ऐसा लगता है कि setSmallestDisplacement बिल्कुल काम नहीं कर रहा है। उस मामले के बारे में विभिन्न पदों रहे हैं लेकिन बिना किसी समाधान के। अगर कोई मेरी मदद कर सकता है या मुझे एक अलग दिशा में इंगित कर सकता है तो मैं इसकी सराहना करता हूं।फ़्यूज्ड स्थान Api setSmallestDisplacement को अनदेखा/काम नहीं कर रहा

मेरी सेवा

public class GPS_Service extends Service implements GoogleApiClient.ConnectionCallbacks, 
    GoogleApiClient.OnConnectionFailedListener, LocationListener { 

private GoogleApiClient mGoogleApiClient; 
private LocationRequest mLocationRequest; 
private int timethresh; 
private int distancethresh; 
protected Location mCurrentLocation; 

@Override 
public IBinder onBind(Intent intent) { 
    return null; 
} 

@Override 
public void onCreate() { 
    super.onCreate(); 

    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addApi(LocationServices.API) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .build(); 
    mGoogleApiClient.connect(); 

} 

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 

    mLocationRequest = new LocationRequest(); 
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); 
    //Set the desired interval for active location updates, in milliseconds. 
    mLocationRequest.setInterval(60* 1000); 
    //Explicitly set the fastest interval for location updates, in milliseconds. 
    mLocationRequest.setFastestInterval(30* 1000); 
    //Set the minimum displacement between location updates in meters 
    mLocationRequest.setSmallestDisplacement(1); // float 


    return super.onStartCommand(intent, flags, startId); 

} 

@Override 
public void onConnected(Bundle bundle) { 
    if (mCurrentLocation == null) { 
     mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); 

    } 
    //Requests location updates from the FusedLocationApi.  
    startLocationUpdates(); 

} 

@Override 
public void onLocationChanged(Location location) { 
    mCurrentLocation = location; 
    //Toast.makeText(this, ""+mCurrentLocation.getLatitude()+","+mCurrentLocation.getLongitude(), Toast.LENGTH_SHORT).show(); 
    System.out.println(""+mCurrentLocation.getLatitude()+","+mCurrentLocation.getLongitude()); 


} 

@Override 
public void onConnectionSuspended(int i) { 
    // The connection to Google Play services was lost for some reason. We call connect() to 
    // attempt to re-establish the connection. 
    mGoogleApiClient.connect(); 
} 


@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 
    Toast.makeText(getApplicationContext(),"Location services connection failed with code " + connectionResult.getErrorCode(), Toast.LENGTH_LONG).show(); 

} 

protected void startLocationUpdates() { 
    LocationServices.FusedLocationApi.requestLocationUpdates(
      mGoogleApiClient, mLocationRequest, this); 

} 

}

उत्तर

4

इस SO question विशेष रूप से CGR के जवाब के अनुसार।

स्थान Request के लिए सेट विस्थापन, डिवाइस को अभी भी स्थानांतरित करने का कोई मौका नहीं है क्योंकि विस्थापन इंटीवाल्स (अंतराल और सबसे तेज़ अंतराल) पर प्राथमिकता लेता है। जैसा कि मैंने अनुमान लगाया था - हो सकता है कि आपने स्थान सेवा के लिए अलग-अलग स्थान रिक्वेस्ट ऑब्जेक्ट (बिना विस्थापन सेट के) पास किया हो। FusedLocationApi.requestLocationUpdates()।

LocationRequest setSmallestDisplacement ( smallestDisplacementMeters फ्लोट)

मीटर में स्थान अद्यतन के बीच न्यूनतम विस्थापन निर्धारित है। डिफ़ॉल्ट रूप से इसका मान 0 है। यह वही ऑब्जेक्ट देता है, ताकि सेटर्स को जंजीर बनाया जा सके।

नोट: ACCESS_COARSE_LOCATION और नहीं ACCESS_FINE_LOCATION साथ अनुप्रयोगों से स्थान अनुरोध स्वचालित रूप से एक धीमी अंतराल के लिए रोक दिए हो जाएगा, और स्थान वस्तु केवल को समझ से परे हो जाएगा सटीकता की एक मोटे स्तर दिखा।

अधिक जानकारी के लिए यह page देखें। इस तरह

2

कोशिश कुछ:

protected void createLocationRequest() { 
    mLocationRequest = new LocationRequest(); 

    mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS); 

    mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS); 

    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); 

    mLocationRequest.setSmallestDisplacement(100); //100 meters 
} 
संबंधित मुद्दे