0
我最後一次所知的位置沒有更新,但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)));
}