作为主题我目前在瑞典,但是当启动我的地图时,它显示我在英格兰。android:mapView不给我正确的用户位置
我的代码如下所示:
private MapListener myMapViewListener;
private MapController mapController;
private GeoPoint test;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
setupListener();
MapView mapView = (MapView) findViewById(R.id.mapview);
mapController = mapView.getController();
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);
mapController.setZoom(7); // defualt zoom
}
private void setupListener() {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
MapListener listener = new MapListener();
MapView mapView = (MapView) findViewById(R.id.mapview);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
test = new GeoPoint((int)location.getLatitude()*1000000, (int)location.getAltitude()*1000000);
mapController.animateTo(test);
}
@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
}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
}
我已经添加了........
<uses-library android:name="com.google.android.maps" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses- permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
</manifest>
.....我的清单。
我使用http://developer.android.com/guide/topics/location/obtaining-user-location.html作为指南。
非常感谢您的帮助!
没有工作,我甚至尝试:\t \t \t双LAT =位置。 getLatitude()* 1000000; \t \t \t double alt = location.getAltitude()* 1000000; \t \t \t test = new GeoPoint((int)lat,(int)alt); \t \t mapController.animateTo(test); – 2011-02-17 20:05:34
@ Gwing-Ben Yuen您正在使用高度而不是经度。 – 2011-02-17 20:06:44