本文介绍了如何从内容的总地址中获取坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在获取位置地址的总地址和坐标,但我只需要在谷歌地图上显示的坐标。在iPhone中怎么可能?

I am getting total address and coordinates of the location address but I need only coordinates to show on the google map. How is it possible in iPhone?

- (void)geocode {
    [SVGeocoder geocode:addressField.text
             completion:^(NSArray *placemarks, NSError *error) {
                 UIAlertView *alertView;

                 if(!error && placemarks) {
                     SVPlacemark *placemark = [placemarks objectAtIndex:0];

                     NSLog(@"%@",placemarks);
                     alertView = [[UIAlertView alloc] initWithTitle:@"Placemark Found!" message:[placemark description] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                 } else {
                     alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[error description] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                 }

                 [alertView show];
                 [alertView release];
             }];

地理编码的响应


推荐答案

试试这个

- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address
{
   double latitude = 0, longitude = 0;
   NSString *esc_addr =  [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
   NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
   NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
   if (result) {
        NSScanner *scanner = [NSScanner scannerWithString:result];
        if ([scanner scanUpToString:@"\"lat\":" intoString:nil] && [scanner scanString:@"\"lat\":" intoString:nil]) {
          [scanner scanDouble:&latitude];
          if ([scanner scanUpToString:@"\"lng\":" intoString:nil] && [scanner scanString:@"\"lng\":" intoString:nil]) {
              [scanner scanDouble:&longitude];
          }
        }
    }
   CLLocationCoordinate2D center;
   center.latitude = latitude;
   center.longitude = longitude;
   return center;
}

这篇关于如何从内容的总地址中获取坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 06:55