前端之家收集整理的这篇文章主要介绍了
android – 如何使用单元格塔找到用户位置?,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
class MyLocationActivity
extends MapActivity {
MapController mapController;
MyPositionOverlay positionOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapController = mapView.getController();
// Configure the map display options
mapView.setSatellite(true);
mapView.setStreetView(true);
mapView.displayZoomControls(false);
mapController.setZoom(17);
// Add the MyPositionOverlay
positionOverlay = new MyPositionOverlay();
List<Overlay> overlays = mapView.getOverlays();
overlays.add(positionOverlay);
LocationManager locationmanager;
String context=Context.LOCATION_SERVICE;
locationmanager=(LocationManager) getSystemService(context);
String provider=LocationManager.NETWORK_PROVIDER;
Location location= locationmanager.getLastKnownLocation(provider);
updateWithNewLocation(location);
}
private void updateWithNewLocation(Location location) {
if(location!=null){
positionOverlay.setLocation(location);
Double lat=location.getLatitude()*1E6;
Double lon=location.getLongitude()*1E6;
GeoPoint point = new GeoPoint(lat.intValue(),lon.intValue());
mapController.animateTo(point);
}
else{
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
原文链接:/android/312336.html