2013-04-01 35 views
1

因爲我不想混淆,我會嘗試與SDK示例代碼來解釋。Android Google Maps v2 - OnMyLocationChangeListener - 它究竟需要什麼?

,一切工作正常 - 除了"onMyLocationChange"回調。

- API 16 & 17 tested 
- updated Play Services Rev.5 
- Tested with ICS Tablet&Phone 

我只是說需要接收位置更新的內容:

UiSettingsDemoActivity implements OnMyLocationChangeListener 

連接它的地圖:

mMap.setOnMyLocationChangeListener(this); 

並實施回調

@Override 
public void onMyLocationChange(Location arg0) { 
    .... 
} 

但是這種方法從來沒有觸發過紅。

釋放從26月注:https://groups.google.com/d/msg/google-maps-android-api-notify/va_IsjNu5-M/QPtoSn69UMgJ - 所以我想這是工作。

編輯:http://code.google.com/p/gmaps-api-issues/issues/detail?id=4644

回答

1

你有沒有在你的應用程序?:

locationListener = new MyLocationListener(); 
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); 

MyLocationListener增加了LocationListener

public class MyLocationListener implements LocationListener 
{ 
static final String TAG = MyLocationListener.class.getSimpleName(); 
@Override 
public void onLocationChanged(Location location) { 
    SGTasksListAppObj.getInstance().currentUserLocation = location; 
    Log.d(TAG, "New location was set to currentUserLocation: "+location.toString()); 

} 

@Override 
public void onProviderDisabled(String provider) { 
    // TODO Auto-generated method stub 
} 

@Override 
public void onProviderEnabled(String provider) { 
    // TODO Auto-generated method stub 
} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 
    // TODO Auto-generated method stub 
} 

} 

更新:

也許你SH烏爾德嘗試:

map.setMyLocationEnabled(boolean boolean); 

方法,並檢查此鏈接:

How to get My Location changed event with Google Maps android API v2?

+0

[鏈接](http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.OnMyLocationChangeListener.html)這是自Rev.5(26.02.2013) – everyman

+0

以來的官方奇怪的Eclipse不承認這種方法。我想我需要更新我的SDK。那麼把我的背單詞關於「沒有......」,但無論如何你必須窗臺爲了設置loicationListener得到的位置變化通知。 –

+0

我只是更新我的應用程序V2 - V1與我有一個自定義LocationListener的,但我認爲,根據Google的執行效果更好。 – everyman

0

你如何測試你的位置是否已經改變?我會假設它會涉及到移動或使用虛擬數據並手動更改位置。你的GPS需要打開嗎?

+0

Wifi/GPS和位置服務已打開 - 當我打開標準的Google地圖應用程序時,它立即可用。我也看到locapi_rpc_glue進程正在淹沒我的日誌。 – everyman

相關問題