objective c - How to implement location search using google maps in ios? -
i building ios app.i using storyboards build screens , have integrated google map in project.
i want location tap in map , want show location in label in airbnb app.i’m unable that,could help.
here code:
- (void)viewdidload { [super viewdidload]; gmscameraposition *camera = [gmscameraposition camerawithlatitude:-33.86 longitude:151.20 zoom:6]; mapview_ = [gmsmapview mapwithframe:cgrectzero camera:camera]; mapview_.mylocationenabled = yes; self.view = mapview_; gmsmarker *marker = [[gmsmarker alloc] init]; marker.position = cllocationcoordinate2dmake(-33.86, 151.20); marker.title = @"sydney"; marker.snippet = @"australia"; marker.map = mapview_; }
help appreciated!
you have use gmsmapviewdelegate
protocol that. precisely, method mapview:didtapatcoordinate:
require , detect tap on map , giving tap's coordinate.
to use method, add following line in viewdidload
:
mapview_.delegate = self;
then in same class implement method:
- (void)mapview:(gmsmapview *)mapview didtapatcoordinate:(cllocationcoordinate2d)coordinate{ // coordinate contains coordinate :) nslog(@"did tap @ coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude); }
update: add marker can following:
- (void)mapview:(gmsmapview *)mapview didtapatcoordinate:(cllocationcoordinate2d)coordinate{ // coordinate contains coordinate :) nslog(@"did tap @ coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude); // create marker , add map cllocationcoordinate2d position = cllocationcoordinate2dmake(coordinate.latitude, coordinate.longitude); gmsmarker *marker = [gmsmarker markerwithposition:position]; marker.appearanimation = kgmsmarkeranimationpop; marker.map = mapview_; // zoom current location gmscameraposition *cameraposition = [gmscameraposition camerawithtarget:position zoom:15.0]; [mapview_ animatetocameraposition:cameraposition]; }
Comments
Post a Comment