这可能是一个新手问题,但我不是百分之百确定。
如何使用Geo points创建Location对象?我想用它来计算两点之间的距离。我已经找到一个帖子上面写着
Location loc1 = new Location("Location");
loc.setLatitude(geoPoint.getLatitudeE6);
loc.setLongitude(geoPoint.getLongitudeE6);
Location loc2 = new Location("Location2");
loc2.setLatitude(geoPoint.getLatitudeE6);
loc2.setLongitude(geoPoint.getLongitudeE6);然后我将使用distanceTo()来获得两点之间的距离。
我的问题是什么是提供商名称?...new位置(“这里是什么?”)那么,我是不是必须在此之前定义一个提供程序呢?我想在for()中使用这段代码来计算更多的GeoPoints。顺便说一句,我必须将E6值转换回正常吗?
发布于 2011-05-18 14:39:49
不完全同意
loc.setLatitude()有两个纬度。所以正确的代码是:
loc.setLatitude( geoPoint.getLatitudeE6() / 1E6);Location()构造函数接受所使用的GPS提供程序的名称。在其他值中,它可以是LocationManager.GPS_PROVIDER或NETWORK_PROVIDER
发布于 2011-05-18 15:27:53
要获得两点之间的距离,可以使用Location类,更准确地说,可以使用distanceBetween静态方法。
该文档很清楚它的作用,但这里有一个快速代码示例:
float[] results = new float[3];
Location.distanceBetween(destLatitude, destLongitude, mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude(), results);
// result in meters, convert it in km
String distance = String.valueOf(Math.round(results[0] / 1000)) + " km");要将分钟/秒转换为度,可以使用Location类的convert方法。
发布于 2012-07-10 13:44:51
Log.i("MapView", "Map distance to mark (in meters): " + myLocation.distanceTo(GeoToLocation(point)) + "m");然后
public Location GeoToLocation(GeoPoint gp) {
Location location = new Location("dummyProvider");
location.setLatitude(gp.getLatitudeE6()/1E6);
location.setLongitude(gp.getLongitudeE6()/1E6);
return location;
}https://stackoverflow.com/questions/6040623
复制相似问题