开发者

How to find address using latitude and longitude [duplicate]

开发者 https://www.devze.com 2023-02-20 07:38 出处:网络
This question already ha开发者_Go百科s answers here: Closed 11 years ago. Possible Duplicate: Convert iPhone GPS to address
This question already ha开发者_Go百科s answers here: Closed 11 years ago.

Possible Duplicate:

Convert iPhone GPS to address

hi,how to find address using latitude and longitude in iphonei


This is called "reverse geocoding". Here is a sample:

http://www.icodeblog.com/2009/12/22/introduction-to-mapkit-in-iphone-os-3-0-part-2/


import

#import "JSON.h"

I'm using json framework from http://code.google.com/p/json-framework download that.

+(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;
}


you can do this in 2 ways

1) CellIdentifier iphone example, its easy.

2) use a google map service from iphone, which can convert your address to Longitude and latitude here is the link

http://maps.google.com/maps/geo?q=###ADDRESS###&;output=###OUTPUT###&;key=###KEY###

Regards Shahid

0

精彩评论

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