如何将用户的GPS位置与可用的GPS位置进行比较?

问题描述 投票:-4回答:1

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

spring-boot android-gps
1个回答
0
投票

您可以使用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...

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.