Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Move Map in Background with Fixed Marker Pin in Objective-C iOS?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.82k
    Comment on it
    1. Install pods named as- pod 'GoogleMaps'
    2. Import <GoogleMaps/GoogleMaps.h> in your class.
    3. 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..
    4. Create an object of GMSMapView as GMSMapView *mapview in an interface of your class.
    5. 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.
    6. Give class to the view as “GMSMapView”, this will only happen after successfully installing GoogleMaps Pods.
    7. Create its IBOutlet in ur respective class as-
    __weak IBOutlet GMSMapView *myMapview;

     

    1. Set the delegates for MapView as-
    @interface YourClassname ()<CLLocationManagerDelegate,GMSMapViewDelegate> and
        myMapview.delegate = self.
    1. Create an object of GMSCameraPosition *camera i.e the position on where the marker should point on the map.
    1. Now create an object of location manager as-CLLocationManager *locationManager.
    1. 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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: