how to find nearest latitude and longitude form current place?

给你一囗甜甜゛ 提交于 2019-12-02 09:33:26
Kumar KL

If you want to calculate based on the co-ordinates , here is simple scenario : Just take all of the "CLLocationCoordinate2D" from your dictionary .

For ex:

MKPointAnnotation *annotaion=[MKPointAnnotaion alloc]alloc];

CLLocationCoordinate2D pointACoordinate = [annotation coordinate];
//  If you have the co-ordinates in hand , then just make " CLLocation *loc2; " using Co-ordinates  

loc2 = [[CLLocation alloc] initWithLatitude:pointACoordinate.latitude longitude:pointACoordinate.longitude];

then put loop or whichever you want to calculate the less distance by comparing with all using this

CLLocationDistance nearLocation=[ location distanceFromLocation:loc2]; // location --> your current Location

If you want to achieve other than it : Then just follow saury answer, they are good to achieve perfectly.

This problem is similar to finding the K Nearest Neighbor (KNN) problem. I will suggest you to go through following links to have an understanding on how to solve your problem

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