0

我创建了一种方法来计算从当前位置到硬编码位置的距离。但它不起作用。计算器不显示距离。这里有什么问题?

public void ourLocation() 

{

    myLocation = new MyLocationOverlay(this, map);
    map.getOverlays().add(myLocation);
    myLocation.enableMyLocation();

    // Find my position
    locationManager = (LocationManager) this
            .getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            20000, 0, this);

    controller = map.getController();

}

我的 onLocationChanged 方法。

public void onLocationChanged(Location location1) {
        // Updating location and zoom
        controller.setCenter(new GeoPoint(
                (int) (location.getLatitude() * 1000000), (int) (location
                        .getLongitude() * 1000000)));
        controller.setZoom(15);

    Criteria crit = new Criteria();
    towers = locationManager.getBestProvider(crit, false);

    location = locationManager.getLastKnownLocation(towers);

    //Trying to get MyPostion.
    Location myLocation = new Location("point A");

    myLocation.setLongitude(location.getLongitude());
    myLocation.setLatitude(location.getLatitude());

    Location locationB = new Location("point B");

    locationB.setLatitude(55777816);
    locationB.setLongitude(12533358);

    float distance = myLocation.distanceTo(locationB);

    //Showing the distance
        AlertDialog alert = new AlertDialog.Builder(GoogleMaps.this)
                .create();
        alert.setTitle((int)distance);

}
4

1 回答 1

0

从外观上看,您正在接收位置更新。Location 对象具有计算到另一个位置的距离的功能。这样你就可以检查你是否在半径范围内。

于 2013-01-07T21:01:48.480 回答