1

因为不想混淆,所以我会尝试用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

4

2 回答 2

1

Have you added a LocationListener in your application?:

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
}

}

Update:

Maybe you should try the:

map.setMyLocationEnabled(boolean boolean);

method, and check this link:

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

于 2013-04-01T23:45:31.257 回答
0

How are you testing whether your location have changed? I would assume it would involve moving around or using dummy data and change the location manually. Does your gps need to be turned on?

于 2013-04-01T23:48:03.500 回答