2011-03-24 50 views
0

在我的應用程序中,我使用位置管理器來獲取經度和緯度。但漫遊到地圖位置的「連接」不會立即與最近的位置「連接」。有時在它工作之前最多需要五次重啓。其他時間需要更多。Android中的位置管理器和速度?

下面是我在做什麼,

LocationManager locationManager;    
String context = Context.LOCATION_SERVICE;   
locationManager = (LocationManager)getSystemService(context);  
String provider = LocationManager.GPS_PROVIDER;  

Location location =locationManager.getLastKnownLocation(provider);   
updateWithNewLocation(location);    

myLocationManager = (LocationManager)getSystemService(
         Context.LOCATION_SERVICE); 

myLocationListener = new MyLocationListener(); 

myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,myLocationListener); 

而且在onLocationChanged

double Lat = argLocation.getLatitude();   
double Long = argLocation.getLongitude();  

Longitude = Double.toString(Long);   
Latitude = Double.toString(Lat); 

我做錯了嗎?

+0

您可以改述「地圖位置的連接沒有立即與最近位置連接」。 ?你到底什麼意思 ?你的位置監聽器onLocationChanged沒有踢入嗎? – ddewaele 2011-03-24 14:53:07

+0

@ddewaele我得到的GPS位置,但漫遊時,它不反映最近的位置,所以我的應用程序的要求是獲得最近的位置提供緊急服務。 – Panache 2011-03-24 15:00:54

回答

0

我注意到你正在使用GPS提供者,在某些情況下確實需要更長的時間才能找到自己。我會使用網絡供應商推薦的起始位置:

Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 

我已經有相當精確的結果,這個初始值,並將其作爲一個不錯的起點,而用戶繼續使用應用程序工作時更好的成績成爲可在後臺進程中使用。 This guide提供了一些有用的最佳實踐。