更新时间:2023-02-27 08:34:28
类MyLocationActivity
扩展MapActivity {
MapController mapController;
MyPositionOverlay positionOverlay;
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
图形页面图形页面=(图形页面)findViewById(R.id.mapview);
mapController = mapView.getController();
//配置图的显示选项
mapView.setSatellite(真正的);
mapView.setStreetView(真正的);
mapView.displayZoomControls(假);
mapController.setZoom(17);
//添加MyPositionOverlay
positionOverlay =新MyPositionOverlay();
名单<覆盖>叠加=调用MapView.getOverlays();
overlays.add(positionOverlay);
LocationManager locationmanager;
字符串情形= Context.LOCATION_SERVICE;
locationmanager =(LocationManager)getSystemService(上下文);
字符串提供商= LocationManager.NETWORK_PROVIDER;
位置位置= locationmanager.getLastKnownLocation(供应商);
updateWithNewLocation(位置);
}
私人无效updateWithNewLocation(位置定位){
如果(位置!= NULL){
positionOverlay.setLocation(位置);
双纬度= location.getLatitude()* 1E6;
双LON = location.getLongitude()* 1E6;
的GeoPoint点=新的GeoPoint(lat.intValue(),lon.intValue());
mapController.animateTo(点);
}
其他{
}
}
@覆盖
保护的布尔isRouteDisplayed(){
// TODO自动生成方法存根
返回false;
}
}
How to find the user location using the cell tower in Android, or how to get the cell location based on the Cell ID in 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;
}
}