- Install pods named as- pod 'GoogleMaps'
- Import <GoogleMaps/GoogleMaps.h> in your class.
- On your view controller where you want to show the map take a UIview & adjust its size according to the size you want to show the map in..
- Create an object of GMSMapView as GMSMapView *mapview in an interface of your class.
- Once the view is placed successfully add a marker or pin image place it on a center of the map so that the map behind the marker/pin moves & pin stays on center always.
- Give class to the view as “GMSMapView”, this will only happen after successfully installing GoogleMaps Pods.
- Create its IBOutlet in ur respective class as-
__weak IBOutlet GMSMapView *myMapview;
- Set the delegates for MapView as-
@interface YourClassname ()<CLLocationManagerDelegate,GMSMapViewDelegate> and
myMapview.delegate = self.
- Create an object of GMSCameraPosition *camera i.e the position on where the marker should point on the map.
- Now create an object of location manager as-CLLocationManager *locationManager.
- Pass the Lat Long of the position where u want the pin to point or the map to move to & you'll see the location will be scrolled on center of the map where your marker/pin is fixed as done in the following function
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
NSLog(@"%@", [locations lastObject]);
CLLocation *location = [locations lastObject];
[manager stopUpdatingLocation];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:location.coordinate.latitude
longitude:location.coordinate.longitude
zoom:12];
mapview = [GMSMapView mapWithFrame:CGRectZero camera:camera];
myMapview.delegate = self;
[myMapview setCamera:camera];
[myMapview addSubview:mapview];
}
0 Comment(s)