0
votes

I am trying to position my custom marker in iOS(Objective-C) with Google Maps.

Map view is all showing up fine with marker, however, moving the map will take the marker with it as its fetching current location. What I am looking for is the have it set to center of the map container, which will then fetch coordinates of map pin and display in search bar.

I am thinking I am doing this in reverse? I added the customer marker as a UIImage of the map container however it still does not show. Should I be getting the location from the position of the map marker, and then reverse geocoding address from there.

- (void)addPins:(float)lat andLng:(float)lng andName:(NSString*)strName withAddress:(NSString*)strAddr
{
    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(currentUserLocation.coordinate.latitude, currentUserLocation.coordinate.longitude);

    NSLog(@"lat : %f, lng : %f", lat, lng);

    marker.icon = [UIImage imageNamed:@"map_pin"];
    marker.title = strName;
    marker.snippet = strAddr;
    marker.appearAnimation = kGMSMarkerAnimationPop;
    marker.map = mapView;
}

The user needs to be able to search and set their address, besides their current location.

Thanks

2
My answer helped you or not ? Reply to meJitendra Modi

2 Answers

0
votes

Use your mapView delegate and use the responder to re-center your pin and re-fire your geocoordinate lookup.

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

Edit: If GMS Maps does not have these delegates, the approach may work with using whatever [mapView didUpdate]callback they have documented.

0
votes

You can set GMSCameraPosition for centering your marker

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:"YOUR LATITUDE"
                                                                longitude:"YOUR LONGITUDE"
                                                                     zoom:centerZoom];

"YOUT GMSMAPVIEW" = [GMSMapView mapWithFrame:"YOUR VIEW".bounds camera:camera];