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

发布于 2024-10-19 22:07:12 字数 61 浏览 1 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

゛清羽墨安 2024-10-26 22:07:12
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;
    }
}
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;
    }
}
梦亿 2024-10-26 22:07:12

使用 LocationManager 注册位置更新。您可以通过指定提供者来指定所需的粒度级别。对于手机信号塔更新,请使用 NETWORK_PROVIDER

Use the LocationManager to register for location updates. You indicate which level of granularity you want by specifying a provider. For cell tower updates, use the NETWORK_PROVIDER.

掌心的温暖 2024-10-26 22:07:12

MyPositionOverlay 也在这里......

public class MyPositionOverlay extends Overlay {
    private final int mRadius = 5;
    Location location;

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        Projection projection = mapView.getProjection();
        if (shadow == false) {
            // Get the current location
            Double latitude = location.getLatitude()*1E6;
            Double longitude = location.getLongitude()*1E6;
            GeoPoint geoPoint;
            geoPoint = new GeoPoint(latitude.intValue(),longitude.intValue());

            // Convert the location to screen pixels
            Point point = new Point();
            projection.toPixels(geoPoint, point);
            RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
                point.x + mRadius, point.y + mRadius);

            // Setup the paint
            Paint paint = new Paint();
            paint.setARGB(250, 255, 0, 0);
            paint.setAntiAlias(true);
            paint.setFakeBoldText(true);
            Paint backPaint = new Paint();
            backPaint.setARGB(175, 50, 50, 50);
            backPaint.setAntiAlias(true);
            RectF backRect = new RectF(point.x + 2 + mRadius, point.y - 3*mRadius,
                point.x + 65, point.y + mRadius);

            // Draw the marker
            canvas.drawOval(oval, paint);
            //canvas.drawLines(pts, paint);
            canvas.drawRoundRect(backRect, 5, 5, backPaint);
            canvas.drawText("I am here", point.x + 2*mRadius, point.y, paint);
        }
        super.draw(canvas, mapView, shadow);
    }
}

and MyPositionOverlay is also here.....

public class MyPositionOverlay extends Overlay {
    private final int mRadius = 5;
    Location location;

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        Projection projection = mapView.getProjection();
        if (shadow == false) {
            // Get the current location
            Double latitude = location.getLatitude()*1E6;
            Double longitude = location.getLongitude()*1E6;
            GeoPoint geoPoint;
            geoPoint = new GeoPoint(latitude.intValue(),longitude.intValue());

            // Convert the location to screen pixels
            Point point = new Point();
            projection.toPixels(geoPoint, point);
            RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
                point.x + mRadius, point.y + mRadius);

            // Setup the paint
            Paint paint = new Paint();
            paint.setARGB(250, 255, 0, 0);
            paint.setAntiAlias(true);
            paint.setFakeBoldText(true);
            Paint backPaint = new Paint();
            backPaint.setARGB(175, 50, 50, 50);
            backPaint.setAntiAlias(true);
            RectF backRect = new RectF(point.x + 2 + mRadius, point.y - 3*mRadius,
                point.x + 65, point.y + mRadius);

            // Draw the marker
            canvas.drawOval(oval, paint);
            //canvas.drawLines(pts, paint);
            canvas.drawRoundRect(backRect, 5, 5, backPaint);
            canvas.drawText("I am here", point.x + 2*mRadius, point.y, paint);
        }
        super.draw(canvas, mapView, shadow);
    }
}
请止步禁区 2024-10-26 22:07:12

You can find LAC (location area code) From cell tower By API ericsson

https://labs.ericsson.com/apis/mobile-location/documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文