用于iphone获取位置的谷歌API不起作用?

用于iphone获取位置的谷歌API不起作用?,iphone,xcode,google-maps,Iphone,Xcode,Google Maps,你好 我正在使用GoogleAPI和这个方法来搜索一个位置,但现在它显示出来了 (610,0,0,0)响应 这是我的密码: -(CLLocationCoordinate2D) addressLocation { NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", [addressField.text str

你好 我正在使用GoogleAPI和这个方法来搜索一个位置,但现在它显示出来了 (610,0,0,0)响应

这是我的密码:

-(CLLocationCoordinate2D) addressLocation {
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                [addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];

double latitude = 0.0;
double longitude = 0.0;

if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
    latitude = [[listItems objectAtIndex:2] doubleValue];
    longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
     //Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;

return location;
}
试试这个:

- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address
{
   double latitude = 0.0;
   double longitude = 0.0;

   NSString *esc_addr =  [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
   NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];

   NSDictionary *googleResponse = [[NSString stringWithContentsOfURL: [NSURL URLWithString: req] encoding: NSUTF8StringEncoding error: NULL] JSONValue];

   NSDictionary    *resultsDict = [googleResponse valueForKey:  @"results"];   // get the results dictionary
   NSDictionary   *geometryDict = [resultsDict valueForKey: @"geometry"];   // geometry dictionary within the  results dictionary
   NSDictionary   *locationDict = [geometryDict valueForKey: @"location"];   // location dictionary within the geometry dictionary

   NSArray *latArray = [locationDict valueForKey: @"lat"];
   NSString *latString = [latArray lastObject];     // (one element) array entries provided by the json parser

   NSArray *lngArray = [locationDict valueForKey: @"lng"];
   NSString *lngString = [lngArray lastObject];     // (one element) array entries provided by the json parser

   CLLocationCoordinate2D location;
   location.latitude = [latString doubleValue];// latitude;
   location.longitude = [lngString doubleValue]; //longitude;

   return location;
}
我之前也发现了同样的问题

可能有一个关于谷歌API服务的问题

希望对你来说是htlp


谢谢。

很好。。很高兴帮助你。享受编码……)