我的最后一个已知位置没有更新,但googlemap.setMyLocationEnable(true)
我的位置正在更新。任何人都可以帮忙吗?这是我的代码:
private void setUpMap() {
if(googlemap == null) {
googlemap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
if(googlemap != null) {
googlemap.setMyLocationEnabled(true);
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
String provider = lm.getBestProvider(new Criteria(), true);
if (provider == null){
onProviderDisabled(provider);
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
Location loc = lm.getLastKnownLocation(provider);
if (loc != null) {
onLocationChanged(loc);
}
googlemap.setOnMapLongClickListener(onLongClickMapSettings());
}
}
}
private OnMapLongClickListener onLongClickMapSettings() {
// TODO Auto-generated method stub
return new OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng arg0) {
// TODO Auto-generated method stub
Log.i(arg0.toString(), "User long clicked");
}
};
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());
googlemap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
googlemap.animateCamera(CameraUpdateFactory.zoomTo(15));
Marker ME = googlemap.addMarker(new MarkerOptions()
.position(latlng)
.title("Current Location(You)")
.snippet("Current")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.user_marker)));
}