地理点与位置

发布于 2024-11-08 03:11:46 字数 520 浏览 1 评论 0原文

这可能是一个菜鸟问题,但我不是 100% 确定。

如何使用地理点制作位置对象?我想用它来获取两点之间的距离。 我已经找到了一个线程,它说

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() 来获取两点之间的距离。

我的问题 提供商名称有何用途? ...新位置(“这是什么???”) 那么我必须先定义一个提供者还是什么? 我想在 for() 中使用此代码来计算更多地理点。 顺便说一句 - 我必须将 E6 值转换回正常值?

This is maybe a noob question but im not 100% sure about it.

How can i make a Location Object using Geo points? I want to use it to get the distance between two points.
I already found a thread where it says

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

and then i would use the distanceTo() to get the distance between the two points.

My Questions
What is the Providername for? ...new Location("What is this here???")
So do i have to define a Provider before or something?
I want to use this code in a for() to calaculate between more GeoPoints.
And btw - i have to convert the E6 Values back to normal?

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

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

发布评论

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

评论(3

别闹i 2024-11-15 03:11:46

loc.setLatitude()并不完全

采用双纬度。所以正确的代码是:

  loc.setLatitude( geoPoint.getLatitudeE6() / 1E6);

Location() 构造函数采用所使用的 GPS 提供商的名称。它可以是 LocationManager.GPS_PROVIDER 或 NETWORK_PROVIDER 以及其他值

Not exactly

loc.setLatitude() takes a double latitude. So the correct code is:

  loc.setLatitude( geoPoint.getLatitudeE6() / 1E6);

Location() constructor take the name of the GPS provider used. It can be LocationManager.GPS_PROVIDER or NETWORK_PROVIDER among other values

老街孤人 2024-11-15 03:11:46

要获取两点之间的距离,您可以使用 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");

要将分钟/秒转换为度数,您可以使用 convert Location 类的方法。

To get the distance between two point you can use the Location class and more precisely the distanceBetween static method.

The doc is quite clear on what it does but here a quick code sample:

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

To convert from minute/second to degree you can use the convert method of the Location class.

陌上青苔 2024-11-15 03:11:46
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;
    }
Log.i("MapView", "Map distance to mark (in meters): " + myLocation.distanceTo(GeoToLocation(point)) + "m");

then

public Location GeoToLocation(GeoPoint gp) {
        Location location = new Location("dummyProvider");
        location.setLatitude(gp.getLatitudeE6()/1E6);
        location.setLongitude(gp.getLongitudeE6()/1E6);
        return location;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文