google maps zoom to current location in ios -


google maps not zoom current location after searching many solution on stack such zoom in current location on map in object c found solution me written in swift current location in google maps swift

code

.h file

#import <uikit/uikit.h> @import googlemaps; @interface branchesviewcontroller : uiviewcontroller <gmsmapviewdelegate,cllocationmanagerdelegate>  @property (weak, nonatomic) iboutlet gmsmapview *mapview; @property (nonatomic, retain) cllocationmanager *locationmanager;  @end 

.m file

// //  branchesviewcontroller.m //  geeks diner // //  created zakaria darwish on 5/15/16. //  copyright © 2016 codebee. rights reserved. //  #import "branchesviewcontroller.h" #import "infowindow.h" #import "splashviewcontroller.h" #import "sharedvariables.h" #import"afnetworking.h" #import "uiwebview+afnetworking.h" #import "sdwebimagecompat.h" #import "sdwebimagedownloaderoperation.h" #import "sdwebimagedownloader.h" #import "mygeekstableviewcontroller.h" #import "geekslocations.h" #import "branchdetailsviewcontroller.h" @import googlemaps;  @interface branchesviewcontroller () <gmsmapviewdelegate>  @end  @implementation branchesviewcontroller {     gmsmarker *marker_1;     bool firstlocationupdate_;     cllocationcoordinate2d *startpoint;     cllocation *mylocation;     nsmutablearray *list;   }    -(void)getcurrentlocationandzoomtoit {    }    //- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { //    gmscameraposition *camera = [gmscameraposition camerawithlatitude:newlocation.coordinate.latitude //                                                            longitude:newlocation.coordinate.longitude //                                                                 zoom:17.0]; //    [self.mapview animatetocameraposition:camera]; //    cllocation *location = newlocation; // // // // // //// ////    let userlocation = locations.last ////    let center = cllocationcoordinate2d(latitude: userlocation!.coordinate.latitude, longitude: userlocation!.coordinate.longitude) //// ////    let camera = gmscameraposition.camerawithlatitude(userlocation!.coordinate.latitude, ////                                                      longitude: userlocation!.coordinate.longitude, zoom: 8) ////    let mapview = gmsmapview.mapwithframe(cgrectzero, camera: camera) ////    mapview.mylocationenabled = true ////    self.view = mapview //// ////    let marker = gmsmarker() ////    marker.position = center ////    marker.title = "current location" ////    marker.snippet = "xxx" ////    marker.map = mapview //// ////    locationmanager.stopupdatinglocation() // }  -(void)mapview:(gmsmapview *)mapview didtapinfowindowofmarker:(gmsmarker *)marker {     nslog(@"tapped");     // need move new view //      branchdetailsviewcontroller *avc =   [[uistoryboard storyboardwithname:@"main" bundle:nil] instantiateviewcontrollerwithidentifier:@"branchdetailviewcontroller"];     uinavigationcontroller *nav  = [[uinavigationcontroller alloc] initwithrootviewcontroller:avc];     //       nav.modaltransitionstyle = uimodaltransitionstylefliphorizontal;     [self presentviewcontroller:nav animated:yes completion:nil];  }     -(uiimage *)getimage :(uiimage *)icon stop:(nsstring *)stopnumber color:(uicolor *)color {     // create label     uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(0, 0, icon.size.width,icon.size.height)];     [label settext:stopnumber];     [label settextcolor:color];     [label setfont:[uifont boldsystemfontofsize:11]];     label.textalignment = nstextalignmentcenter;      //start drawing     uigraphicsbeginimagecontext(icon.size);      //draw image     [icon drawinrect:cgrectmake(0, 0, icon.size.width, icon.size.height)];      //draw label     [label drawtextinrect:cgrectmake((icon.size.width - label.frame.size.width)/2, -5, label.frame.size.width, label.frame.size.height)];      //get final image     uiimage *resultimage  = uigraphicsgetimagefromcurrentimagecontext();      uigraphicsendimagecontext();     return resultimage; }     - (void)viewdidload {     [super viewdidload];       self.mapview.delegate = self;      self.locationmanager = [[cllocationmanager alloc] init] ;     self.locationmanager.delegate = self;     [self.locationmanager requestwheninuseauthorization];     self.locationmanager.desiredaccuracy = kcllocationaccuracybestfornavigation ;     [self.locationmanager setdistancefilter:10.0f] ;     [self.locationmanager startupdatinglocation];      //    uibarbuttonitem *rightbarbuttonitem = [[uibarbuttonitem alloc] initwithcustomview:[[uiview alloc] initwithframe:cgrectmake(0, 0, 0, 0)]];     //    // width equivalent system default done button's (which appears on pushed view in case).     //    rightbarbuttonitem.enabled = no;     //    self.navigationitem.leftbarbuttonitem = rightbarbuttonitem;     [self getgeekslocations];    }   - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation            fromlocation:(cllocation *)oldlocation {        [self.locationmanager stopupdatinglocation];     cllocationcoordinate2d zoomlocation;   //  zoomlocation.latitude = self.mapview.mylocation.location.coordinate.latitude;   //  zoomlocation.longitude= yourmapview.userlocation.location.coordinate.longitude;     // 2   //  mkcoordinateregion viewregion = mkcoordinateregionmakewithdistance(zoomlocation, 0.5*1609.344, 0.5*1609.344);     // 3    // [self.mapview setregion:viewregion animated:yes];   //        [self.locationmanager stopupdatinglocation]; //         zoomlocation.latitude = self.mapview.userlocation.location.coordinate.latitude; //        zoomlocation.longitude= self.mapview.userlocation.location.coordinate.longitude; //        // 2 //        mkcoordinateregion viewregion = mkcoordinateregionmakewithdistance(zoomlocation, 0.5*1609.344, 0.5*1609.344); //        // 3 //        [self.mapview setregion:viewregion animated:yes]; } 

so 1 me ??

you can pan map or change perspective little latency. bearing, tilt, location , zoom level of map can controlled programmatically via gmscameraposition object.

you can use -animatetozoom: on gmsmapview, or can create gmscameraposition , set coordinate , zoom level , use -animatetocameraposition: or create gmscameraupdate , use -animatewithcameraupdate:

gmscameraposition *cameraposition = [gmscameraposition camerawithlatitude:latitude longitude:longitude zoom:11.0];  [self.mapview animatetocameraposition:cameraposition]; 

or

gmscameraupdate *update = [gmscameraupdate zoomto:11.0]; [self.mapview animatewithcameraupdate:update]; 

or

[self.mapview animatetozoom:11.0];