gpt4 book ai didi

android - 如何使用手机信号塔查找用户位置?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:03:08 26 4
gpt4 key购买 nike

如何在Android中使用手机信号塔找到用户位置,或者在Android中如何根据Cell ID获取手机位置?

最佳答案

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 - 如何使用手机信号塔查找用户位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5184877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com