开发者

Near me by miles Objective-C

开发者 https://www.devze.com 2023-04-11 21:05 出处:网络
I\'m trying to make near places like this: I searched all kinds of tuturials in the internet with the google api and some others,but i cant get a good aproach to do it,i think i have to send a开发者

I'm trying to make near places like this:

Near me by miles Objective-C

I searched all kinds of tuturials in the internet with the google api and some others,but i cant get a good aproach to do it,i think i have to send a开发者_StackOverflow request to google api and it wil return me some data,but im completely lost in this part...I have all the adress i want to sent,but only it. Anyone knows a good tutorial or direction to look?


You can calculate the distance between two geographic points using the Core Location API.

The process of finding the geolocation based on the address is known as Forward Geocoding and is not supported by the iOS.

For apple documentation:

Many geocoding services allow you to perform conversions in either direction but iOS currently supports only reverse geocoding, which converts a latitude and longitude into a placemark. If you want to convert placemark information into a latitude and longitude—a process known as forward geocoding—you would need to find an appropriate third-party service to use.

Since you have the address, you can perform the forward geocoding using the google api. You can send a request like:

http://maps.google.com/maps/api/geocode/json?address=Padre+Chagas+Porto+Alegre&sensor=false

And then parse the location of the place and create a CLLocation object with the Latitude and the Longitude.

At this point you solved the problem of finding the destination geolocation. Now all that you need to do is to get the user current location using Core Location, using something like to create the Location Manager:

- (void)getLocation 
{
  _clManager = [[CLLocationManager alloc] init];
  _clManager.delegate = self;
  if  (! [CLLocationManager locationServicesEnabled]) 
      return; 

  [_clManager startUpdatingLocation]; 
}

And calculate the distance when you get an update of the users location:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation                                            
{ 
    CLLocationDistance distance = [newLocation distanceFromLocation:<destiny_location>];
    [_clManager stopUpdatingLocation]; 
    [self.tableView reloadData];
}

The returned distance will be in meters. It measures a straight line from the user location until the destination point.


You could use a web service that translates an address into a latitude and longitude coordinate, and then given any other coordinate pair like the user's current location, you could compute the distance between them.

I don't know the mathematics bethink that calculation, but a quick search turned this up: http://www.movable-type.co.uk/scripts/latlong.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号