objective c - Reverse Geocoding using google maps api iOS -
i doing reverse geocoding using following code
- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { curloc=newlocation; if (curloc != nil) { latitude=curloc.coordinate.latitude; longitude=curloc.coordinate.longitude; //[self loadmap:latitude second:longitude]; [self markerpoint:latitude+0.04 second:longitude+0.1 third:latitude-0.04 forth:longitude-0.1]; nserror *error; nsstring *lookupstring = [nsurl urlwithstring:[nsstring stringwithformat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",latitude,longitude]]; nslog(@"url: %@",lookupstring); lookupstring = [lookupstring stringbyreplacingoccurrencesofstring:@" " withstring:@"+"]; nsdata *jsonresponse = [nsdata datawithcontentsofurl:[nsurl urlwithstring:lookupstring]]; nsdictionary *jsondict = [nsjsonserialization jsonobjectwithdata:jsonresponse options:kniloptions error:&error]; self.locationarray = [[jsondict valueforkey:@"results"] valueforkey:@"formatted_address"]; int total = self.locationarray.count; nslog(@"locationarray count: %d", self.locationarray.count); (int = 0; < total; i++) { nsstring *statusstring = [jsondict valueforkey:@"status"]; nslog(@"json response status:%@", statusstring); nslog(@"address: %@", [self.locationarray objectatindex:i]); } } }
now getting error :
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[nsurl stringbyreplacingoccurrencesofstring:withstring:]: unrecognized selector sent instance 0xbce98c0' *** first throw call stack: ( 0 corefoundation 0x034551e4 __exceptionpreprocess + 180 1 libobjc.a.dylib 0x031a98e5 objc_exception_throw + 44 2 corefoundation 0x034f2243 -[nsobject(nsobject) doesnotrecognizeselector:] + 275 3 corefoundation 0x0344550b ___forwarding___ + 1019 4 corefoundation 0x034450ee _cf_forwarding_prep_0 + 14 5 matchpoint 0x00017fad -[icsviewcontroller locationmanager:didupdatetolocation:fromlocation:] + 813 6 corelocation 0x0164655e cllocationcoordinate2dgetdistancefrom + 18294 7 corelocation 0x01645af4 cllocationcoordinate2dgetdistancefrom + 15628 8 corelocation 0x01642e40 cllocationcoordinate2dgetdistancefrom + 4184 9 corelocation 0x0163c680 clclientinvalidate + 996 10 corefoundation 0x034140b0 __cfrunloop_is_calling_out_to_a_block__ + 16 11 corefoundation 0x033dd339 __cfrunloopdoblocks + 361 12 corefoundation 0x033fb753 __cfrunlooprun + 2355 13 corefoundation 0x033fa9d3 cfrunlooprunspecific + 467 14 corefoundation 0x033fa7eb cfrunloopruninmode + 123 15 graphicsservices 0x051f05ee gseventrunmodal + 192 16 graphicsservices 0x051f042b gseventrun + 104 17 uikit 0x01e69f9b uiapplicationmain + 1225 18 matchpoint 0x0001d9fd main + 141 19 libdyld.dylib 0x03d206d9 start + 1 20 ??? 0x00000001 0x0 + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception (lldb)
provide valid latitude , longitude static , check first. after got success use dynamic latitude , longitude
-(void)getgoogleadrressfromlatlong : (cgfloat)lat lon:(cgfloat)lon{ //[self showloadingview:@"loading.."]; nserror *error = nil; nsstring *lookupstring = [nsstring stringwithformat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false", lat,lon]; lookupstring = [lookupstring stringbyreplacingoccurrencesofstring:@" " withstring:@"+"]; nsdata *jsonresponse = [nsdata datawithcontentsofurl:[nsurl urlwithstring:lookupstring]]; nsdictionary *jsondict = [nsjsonserialization jsonobjectwithdata:jsonresponse options:kniloptions error:&error]; // nslog(@"%@",jsondict); nsarray* jsonresults = [jsondict objectforkey:@"results"]; // nslog(@"%@",jsonresults); }
Comments
Post a Comment