【问题标题】:How to compare the user's GPS position with an available GPS location?如何将用户的 GPS 位置与可用的 GPS 位置进行比较?
【发布时间】:2019-09-04 09:44:21
【问题描述】:

我在应用程序 android 中有用户 GPS 位置的经度和纬度。而且我必须将其他 GPS 位置存储在 postgresql 数据库中(现在我还没有存储的想法)。现在我想通过使用 Spring boot 将位置从 android 发送到服务器来检查用户是否是该位置?我现在该怎么办?请给我一些建议。非常感谢。

【问题讨论】:

  • 我搜索了很多,但与我的问题不符。如果你不赞成,请告诉我理由。谢谢

标签: spring-boot android-gps


【解决方案1】:

您可以使用 API 调用从服务器获取位置,并使用 Location.distanceTo(android.location.Location) 将坐标与当前位置进行比较

//fetch location from server
double lon = 12.227458, lat = 22.456545;

//create new location instance with fetched coordinates
Location locationFromServer = new Location();
locationFromServer.setLongitude(lon);
locationFromServer.setLatitude(lat);

//some method returns the current location
Location current = getCurrentLocation();

//compare locations
double distance = current.distanceTo(locationFromServer);

//do whatever you want with distance...

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-28
    • 2013-01-08
    • 2015-07-21
    • 2016-05-16
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多