map - How to get Latitude and longitude from typed address by a user in Ios 6 -
i new in ios. , learning mapkit , corelocation. have 2 view controllers in program , in first view controller there text field there user can type address. , button. after fill address if user tap on button redirect second view controller map view controller. there 2 annotation. 1 user's current location , user's typed address. can please tell me how lat, long user's typed address , show annotation on map view lat long.
thanks in advance.
here code
#import <mapkit/mapkit.h> #import <corelocation/corelocation.h> +(cllocationcoordinate2d) getlocationfromaddressstring:(nsstring*) addressstr { double latitude = 0, longitude = 0; nsstring *esc_addr = [addressstr 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; }
then call method
coordinates = [self getlocationfromaddressstring:@"address"];
Comments
Post a Comment