Check if the user location is near of some points

别说谁变了你拦得住时间么 提交于 2019-12-12 02:49:54

问题


I have a question about GPS alarm.

I have some points (latitude and longitude). I need a way to check if the user location is near to some of these points (approximately are 1800 points).

If I remember correctly there is a best practice to do this: to be notified when GPS position is in a certain region. This allows for optimizations regarding the battery.

Can you give me any suggestions?


回答1:


1800 points as per 1800 different regions to be monitored?

It is not possible. See here:

For this reason, Core Location limits to 20 the number of regions that may be simultaneously monitored by a single app.

If you have more than 20 regions to be monitored, this is what you can do:-

  1. When the user launches your app, get the user's location and send the location to your server
  2. After the server gets the user location, gathers all the points within N Kilometres (KM) radius.
  3. If the points within N KM are less than 20, then send all the points to your user to be monitored.
  4. If the points within N KM are more than 20, your server has to reduce the points based on the smaller radius (eg: N-1 KM)

I have developed a region monitoring app myself and this is what we do.




回答2:


Define what you mean by near to some of these points.

You could use the haversine formula to calculate the distance between your current location and each of the set of test points. The calculation involves a fair number of trig functions so could work out computationally intensive but depending upon your application it may not be necessary to recalculate more than once a minute or so.



来源:https://stackoverflow.com/questions/23545309/check-if-the-user-location-is-near-of-some-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!