我创建了一种方法来计算从当前位置到硬编码位置的距离。但它不起作用。计算器不显示距离。这里有什么问题?
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);
}