ios - map geocode API gives Null response -
i'm using below code getting geocode response of particular address,
nsstring *address = @"doha,qatar"; nslog(@"address : %@",address); nsstring *esc_addr = [address stringbyaddingpercentescapesusingencoding: nsutf8stringencoding]; nsstring *req = [nsstring stringwithformat: @"http://www.maps.google.com/maps/api/geocode/json?address=%@&sensor=false", esc_addr]; nsurl *url=[nsurl urlwithstring:req]; nslog(@"url : %@",url); nsdata *data=[nsdata datawithcontentsofurl:url]; nslog(@"data : %@",data); nserror *error=nil; id response=[nsjsonserialization jsonobjectwithdata:data options: nsjsonreadingmutablecontainers error:&error]; nslog(@"the json object: %@ or error is: %@", response, error);
but response null.
the response,
2014-11-27 16:35:48.961 myproj[15279:254055] address : doha,qatar 2014-11-27 16:35:48.961 myproj[15279:254055] url : http://www.maps.google.com/maps/api/geocode/json?address=doha,qatar&sensor=false 2014-11-27 16:35:49.005 myproj[15279:254055] data : (null) 2014-11-27 16:35:49.008 myproj[15279:254055] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'data parameter nil'
but when open url in brows gives output as,
{ "results" : [ { "address_components" : [ { "long_name" : "doha", "short_name" : "doha", "types" : [ "locality", "political" ] }, { "long_name" : "doha", "short_name" : "doha", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "qatar", "short_name" : "qa", "types" : [ "country", "political" ] } ], "formatted_address" : "doha, qatar", "geometry" : { "bounds" : { "northeast" : { "lat" : 25.4125783, "lng" : 51.6281212 }, "southwest" : { "lat" : 25.1954283, "lng" : 51.4307964 } }, "location" : { "lat" : 25.286667, "lng" : 51.533333 }, "location_type" : "approximate", "viewport" : { "northeast" : { "lat" : 25.4125783, "lng" : 51.6281212 }, "southwest" : { "lat" : 25.1954283, "lng" : 51.4307964 } } }, "types" : [ "locality", "political" ] } ], "status" : "ok" }
what reason null response,
thanks suggestion.
i tested code , works fine.
data parameter not null.it contains info of json.
so,maybe have check these
- the version of google maps sdk(i use 1.8.0.8950-not newest)
- the initialization of gms services
- your api key google maps.
Comments
Post a Comment