我正在嘗試獲取用戶位置,到目前爲止,我可以獲得地圖上顯示的3個商店,但是我無法找到我目前的位置,這是通過和模擬器,我已經實現了LocationListener方法,但它看起來像方法(onLocationChaged)永遠不會被調用,在OnCreate方法中,我已經指定了我的3個商店,它在地圖上很好地顯示,但不是我的當前位置,我甚至沒有右上角的「raider/round icon」將我帶到目前的位置,我不確定我錯過了什麼。GOOGLE MAPS V2 - 獲取當前用戶位置
Java代碼:
public class LocateStore extends FragmentActivity implements LocationListener{
static final LatLng ARCADIA = new LatLng(-25.746318, 28.221322999999984);
static final LatLng HATFIELD = new LatLng(-25.7487333, 28.238043199999993);
static final LatLng CENTURION = new LatLng(-25.8602778, 28.189444399999957);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_locate_store);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
Marker aracdia = map.addMarker(new MarkerOptions().position(ARCADIA).title("Arcadia").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_small)));
Marker hatfield = map.addMarker(new MarkerOptions().position(HATFIELD).title("Hatfield").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_small)));
Marker centurion = map.addMarker(new MarkerOptions().position(CENTURION).title("Centurion").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_small)));
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
map.clear();
MarkerOptions mp = new MarkerOptions();
mp.position(new LatLng(location.getLatitude(), location.getLongitude()));
mp.title("my position");
map.addMarker(mp);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 16));
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
}
當你打開地圖你沒有看到一個藍色的圓圈顯示你的位置? – erdomester