ios - Google Places API results not showing on map? -
so have google places api working (entering url in browser displays results), yet none of results displayed on actual map. why this? using web key not ios know common error not that.
code:
-(void) querygoogleplaces: (nsstring *) googletype { nsstring* url = [nsstring stringwithformat:@"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=removed stackoverflow&radius=5000&types=atm&sensor=true&key=removedforstackoverflow"]; //formulate string url object. nsurl *googlerequesturl=[nsurl urlwithstring:url]; // retrieve results of url. dispatch_async(kbgqueue, ^{ nsdata* data = [nsdata datawithcontentsofurl: googlerequesturl]; [self performselectoronmainthread:@selector(fetcheddata:) withobject:data waituntildone:yes]; }); } -(void)fetcheddata:(nsdata *)responsedata { //parse out json data nserror* error; nsdictionary* json = [nsjsonserialization jsonobjectwithdata:responsedata options:kniloptions error:&error]; //the results google array obtained nsdictionary object key "results". nsarray* places = [json objectforkey:@"results"]; //write out data console. nslog(@"google data: %@", places); }
the google places api can used query places in huge google database. map doesn't show these places (there millions of them) , fact query 1 of them doesn't mean should added in map. solution once place coordinates add marker.
the fact after query on google maps app can see marker representation of place queried feature of google maps app built on top of google places api + google map sdk , after query adds own marker.
so algorithm is: 1) search (google places api) 2) place coordinates , types (a place can have more 1 type; list provided link in gmsplace class reference: https://developers.google.com/places/supported_types ) 3) add right marker (depending on type) on right coordinate.
as final note notice how google map still show places if didn't for: google choice, show considered relevant places. @ end shouldn't think see in google maps app see google maps sdk map: 1 built on top of other difficult spot @ first glance information comes (certainly google used coherent graphics between app , sdk!). see difference compare side side portion of same map on google maps app , app using google maps sdk.
Comments
Post a Comment