2011-03-29 41 views

回答

0

進口

#import "JSON.h" 

我使用json框架 http://code.google.com/p/json-framework dow nload那個。

+(NSString *) getLocation:(double) lattitude logitude:(double) longitude 
{ 
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",lattitude,longitude]; 


    NSURL *urlFromString = [NSURL URLWithString:urlString]; 
    NSStringEncoding encodingType = NSUTF8StringEncoding; 
    NSString *reverseGeoString = [NSString stringWithContentsOfURL:urlFromString encoding:encodingType error:nil]; 

    NSDictionary *locationResult = [reverseGeoString JSONValue]; 
    NSString *status = (NSString *)[locationResult objectForKey:@"status"]; 
    NSString *retVal = nil; 
    if([status isEqualToString:@"OK"]) 
    { 
     NSArray *results = [locationResult objectForKey:@"results"]; 
     if([results count] > 0) 
     { 
      NSDictionary *address=[results objectAtIndex:0]; 
      retVal = [address objectForKey:@"formatted_address"]; 
     } 


    } 
    return retVal; 
} 
相關問題