2011-04-21 136 views
1

我已经提供了该地址,并告诉我找如何获得当前位置?

http://maps.google.com/maps/geo?q=address&output=csv 

的当前位置是什么样的地址是这样的,我怎么能得到这个信息。这是API吗?

请帮

回答

2

想,如果你给http://maps.google.com/maps/geo?q=newyork&output=csv,其结果将是 200, 4,40.7143528,-74.0059731。最后2个值表示纽约的经度和纬度值...我希望它能帮助你。如果你把这个URL集成到你的应用中,你可以获得坐标并用它们来显示在iPhone中的MKMapView地图。

0

602,0,0,0

这是你的位置坐标。并根据谷歌地图你位于enter image description here这里

+0

你怎么知道OP的位置? :) – AbdullahC 2011-04-21 06:41:34

+0

没有人在地址位置键入ur地址和csv格式写在你想要的结果像json等格式 – Exception 2011-04-21 06:44:28

+0

现在什么是OP? – 2011-04-21 06:44:55

0

由于你可以得到一个地址的经度和纬度。如果您请求此网址并使用您想要查找坐标的地址,则可以获得4个值作为响应。您可以使用此功能来获得一个位置的对象与纬度和记录您的地址:

-(CLLocationCoordinate2D) addressLocation:(NSString *)address { 
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
       [address 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; 
} 

你可以找到更多的帮助,在这里:http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial

+0

这是json格式的纬度和长度“Point”:{ “坐标”:[-119.9590257,36.2552300,0] } – Exception 2011-04-21 06:48:05

+0

你是怎么得到这个json的? – 2011-04-21 06:49:08

+0

,这个地址http://maps.google.com/maps/geo?q=Vanguard,CA,%20United%20States&output=json – Exception 2011-04-21 06:50:35