我在SupportMapFragment中有一个GoogleMap。它在初始显示中工作正常。移动相机,并添加圆圈。但是,在从儿童活动回来之后,moveCamera和addCircle停止了工作。
@Override
public void onConnected(Bundle arg0) {
Log.d("Main Activity",
"onConnected called");
mMap.setOnMarkerClickListener(this);
mMap.setOnCameraChangeListener(this);
mMap.setOnMyLocationChangeListener(this);
// Display the connection status
Location loc = mLocationClient.getLastLocation();
mGeolocation = new LatLng(loc.getLatitude(),loc.getLongitude());
Log.d("GeoLocation",
"latitue:"+mGeolocation.latitude+" longitude:" + mGeolocation.longitude);
if(mMap.getMyLocation()==null)
Log.d("GeoLocation",
"mMap location not set yet");
else
Log.d("GeoLocation",
"mMap location-----latitue:"+ mMap.getMyLocation().getLatitude()+" longitude:" + mMap.getMyLocation().getLongitude());
CameraPosition targetPosition = new CameraPosition.Builder().target(mGeolocation)
.zoom(12.0f)
.bearing(0)
.tilt(25)
.build();
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(targetPosition));
CircleOptions circleParam = new CircleOptions()
.center(mGeolocation)
.radius(MAX_DISTANCE)
.strokeColor(Color.BLUE)
.strokeWidth(5)
.visible(true);
mMap.addCircle(circleParam);
}
@Override
public boolean onMarkerClick(Marker marker) {
Vendor v = listedVendors.get(marker.getId());
if( v!=null){
Intent intent = new Intent(this, MenuActivity.class);
intent.putExtra(EXTRA_VENDOR, v);
intent.putExtra(EXTRA_GEO, mGeolocation);
intent.putExtra(EXTRA_CURRENTADDRESS, mCurrentAddress);
startActivity(intent);
}
return false;
}
@Override
public void onPause() {
Log.d("Main Activity",
"OnPause called");
super.onPause();
if (mLocationClient != null) {
mLocationClient.disconnect();
}`
}
也不会调用onCameraChange事件。
提前感谢您的帮助。
答案 0 :(得分:1)
OK!最后,我自己想出了问题。不知何故,我将mLocationClient声明为活动的静态成员
private static LocationClient mLocationClient;
问题是由"静电" (我不知道为什么。因为它是私有的,除了它们被访问的方式之外应该是相同的)。删除'静态'来自上述陈述的属性,现在一切正常。