Android Google Maps v2 - OnMyLocationChangeListener - 它究竟需要什么?

时间:2013-04-01 23:35:18

标签: android google-maps-android-api-2

因为我不想混淆,我将尝试用SDK示例代码解释。

一切正常 - 除了"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) {
    ....
}

但这种方法永远不会被触发。

从2月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

2 个答案:

答案 0 :(得分:1)

您是否在申请中添加了LocationListener?:

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

MyLocationListener:

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
}

}

<强>更新

也许你应该尝试:

map.setMyLocationEnabled(boolean boolean);

方法,并检查此链接:

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

答案 1 :(得分:0)

您如何测试您的位置是否已更改?我认为它会涉及到移动或使用虚拟数据并手动更改位置。你的gps需要打开吗?