मैं Google API और MapActivity उपयोग कर रहा हूँ, MapView आदि ..
जब मैं मैं इस कोड का उपयोग पहली बार अपना वर्तमान स्थान प्राप्त करने की आवश्यकता:क्या मुझे हर बार स्थान अपडेट के लिए पूछने पर एंड्रॉइड LocationManager.getBestProvider का उपयोग करना चाहिए?
myLocationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
// Sets the criteria for a fine and low power provider
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
crit.setPowerRequirement(Criteria.POWER_LOW);
// Gets the best matched provider, and only if it's on
String provider = myLocationManager.getBestProvider(crit, true);
// If there are no location providers available
if (provider == null){
OnClickListener listener = new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Closes the activity
finish();
}
};
Utils.getInstance().showAlertDialog(this, R.string.warning_dialog_title,
R.string.no_location_providers_error_message,
android.R.drawable.ic_dialog_alert, false, listener);
}
// Location services is enabled
else{
myLocationListener = new MyLocationListener();
myLocationManager.requestLocationUpdates(
provider,
0,
0,
myLocationListener);
// TODO - put a marker in my location
GeoPoint currentGeoPoint = MapUtils.getInstance().
getCurrentLocation(myLocationManager, provider);
// Center to the current location
centerLocation(currentGeoPoint, MAX_ZOOM);
}
मैं भी एक "वापस वर्तमान स्थान के लिए है बटन "- जब उपयोगकर्ता नक्शे को चारों ओर ले जाता है और जल्दी से अपने वर्तमान स्थान पर लौटना चाहता है।
मेरे सवाल है, मैं getBestProvider()
विधि हर बार मैं स्थान की जानकारी प्राप्त करना चाहते हैं इस्तेमाल करना चाहिए?
मैं पिछले चुना प्रदाता बचत हो सकती है, लेकिन स्थिति हर दूसरे को बदल सकता है:
- उपयोगकर्ता बंद कर दिया जीपीएस
- कोई जीपीएस संकेत
- NETWORK_PROVIDER वर्तमान स्थिति
- आदि में बेहतर है ..
सही दृष्टिकोण क्या है?
http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way- टू-मिल-उन-वर्तमान स्थान में एक/3145655 # 3145655। लिंक देखें। आपको अपने प्रश्नों के उत्तर मिल सकते हैं। – Raghunandan
यह अभी भी मेरे प्रश्न का उत्तर नहीं देता है। मेरा कोड भी काम करता है। लेकिन क्या मुझे हर बार GetBestProvider को कॉल नहीं करना चाहिए? मेरी राय में हाँ .. –
http://developer.android.com/guide/topics/location/strategies.html#BestEstimate। आपको शायद इस लिंक से गुजरना चाहिए। – Raghunandan