如何使用手机信号塔查找用户的位置? [英] How to find user location using cell tower?

查看:1608
本文介绍了如何使用手机信号塔查找用户的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用手机信号塔在Android中找到用户位置,或者如何基于Android中的小区ID获取单元位置?

解决方案

 类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;
    }
}

这篇关于如何使用手机信号塔查找用户的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆