【问题标题】:How to find user location using cell tower?如何使用手机信号塔查找用户位置?
【发布时间】:2011-07-08 06:41:21
【问题描述】:

在Android中如何通过基站获取用户位置,或者在Android中如何根据Cell ID获取用户位置?

【问题讨论】:

    标签: android location


    【解决方案1】:
    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;
        }
    }
    

    【讨论】:

    • 使用最后一个已知位置可能会导致非常不准确的结果。小心。
    • 这需要 GPS 吗?
    • 这是必需的 GPS 吗?如果有任何解决方案,我想在不使用 GPS 的情况下获取位置,请提供解决方案。谢谢
    • 解决方案中使用的信号塔信息在哪里?
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 解决方案与提出的问题无关。
      【解决方案4】:

      您可以通过 API ericsson 从手机信号塔找到 LAC(位置区号)

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多