GMSMapView myLocation dot is overlapped with custom pins - ios

I'm using GoogleMaps SDK in my iOS project.
myLocationEnabled property is set to YES.
I expect the user location pin hovering over all other pins like it does on Android. But for some reason it is overlapped with other map pins.
Googling didn't give me anybody with similar problem. What could I do wrong? I'm using standard GMSMapView workflow when adding pins on the map.
GMSMarker * marker = [[GMSMarker alloc]init];
CLLocationCoordinate2D coordinate;
//cluster - is just an object of business logic
coordinate.latitude = [cluster.latitude floatValue];
coordinate.longitude =[cluster.longitude floatValue];
[marker setIcon:markerIcon];
[marker setPosition:coordinate];
[marker setUserData:cluster];
[marker setMap:mapView_];

Related

MKPolyline replacement causes MKTileOverlay to flash on map since iOS 13

I have an MKMapView that has a MKTileOverlay so that I can show Open Street Map tiles:
NSString *templateURL = #"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
self.tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:templateURL];
self.tileOverlay.canReplaceMapContent = YES;
[self.mapView addOverlay:self.tileOverlay level:MKOverlayLevelAboveLabels];
I also want to show an MKPolyline from my current location to Apple Park in Cupertino. This polyline needs to be updated as I move, and since an MKPolyline object isn't mutable, I have to remove it and add it for each location update:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray*)locations {
self.currentLocation = userLocation;
// Update polyline
CLLocationCoordinate2D applePark = CLLocationCoordinate2DMake(37.334626, -122.008895);
[self buildPolylineWithDestinationLocation:applePark];
}
- (void)buildPolylineWithDestinationLocation:(CLLocationCoordinate2D)coordinate {
// Remove the polyline each time so we can redraw it
if (self.polylineApple) {
[self.mapView removeOverlay:self.polylineApple];
}
// Get current location
CLLocation *location = self.currentLocation;
CLLocationCoordinate2D currentLocation = location.coordinate;
CLLocationCoordinate2D points[2];
points[0] = currentLocation;
points[1] = coordinate;
// Remove all route polylines
MKPolyline *oldPolyline = self.polylineApple;
// Draw a line
self.polylineApple = [MKPolyline polylineWithCoordinates:points count:2];
[self.mapView addOverlay:self.polylineApple];
if (oldPolyline) {
[self.mapView removeOverlay:oldPolyline];
oldPolyline = nil;
}
}
The problem is, this used to work great in older versions of iOS, but ever since iOS 13 this has caused the tiles to be redrawn each time that MKPolyline is removed and added:
Is this just an iOS 13 bug, or is there something I need to fix in my code to make this not happen?
As I know since iOS 8, I have seen this issue. Not always but some times.
This issue is linked to 2 things:
1) The action every second to remove and add again a polyline will ask the MKMapView to redrawn the part with the polyline and as a consequence the MKTileOverlay below.
2) If the tile's size (in KB, not the resolution) is low, the issue may not be present.
The best advice I can give to you is to add you own view to the MKMapView and update this own view by calling setNeedsDisplay. It will trigger the draw method where you can convert the map points (latitude, longitude) to screen points and draw the line.
Edit: A link speaking about MKTileOverlay reload issue
https://forums.developer.apple.com/message/313677#313677

Google Maps iOS SDK - Stop deselecting marker on map tap

I am adding a simple marker to my mapView, like so:
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(40.763981, -73.971647);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.map = self.mapView;
marker.snippet = #"My Marker";
self.mapView.selectedMarker = marker;
As you can see I select the marker upon placement, however I want to keep this marker selected, showing the infoview, at all times it is on the map.
Currently, if I tap elsewhere on the map, the infoview is hidden (but the marker stays)

Centering custom marker GMSMapView

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
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.
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];

Map view not focus on annotation

Hello i am new to ios and showing an annoatation on map view using lat and long coming from server.
I have one view controller in which i am adding map and showing position of lat and long. But my problem is whenever i am adding annotation map is not focusing on annotattion insted of it everytime i want pinch map view then map is going to at annoatation i dont know why this is happening?
zoomLocation.latitude = latmpa.doubleValue;
zoomLocation.longitude = logmpa.doubleValue;
annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = zoomLocation;
annotationPoint.title = #"masjid....";
[mapView selectAnnotation:annotationPoint animated:YES];
[mapView addAnnotation:annotationPoint];
here is my code adding in viewwillappera
You need to center the map by use the following code.
mapView.centerCoordinate = annotationPoint.coordinate;
Milan's solution does what you need without animation.
If you want to do this with animation, you should use:
[mapView setCenterCoordinate:location animated:YES];

get specific marker using his coordinates in google maps for ios

I am using Google Maps in my app for IOS. I have added several markers in a map and now I need to get a specific one using its coordinates.
I used:
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
but I think I need to create a new marker, not to get one created before.
One way to do this is to have an NSMutableArray of the markers and search throughout
them.
for (GMSMarker *marker in arrayOfMarkers){
if(marker.position.latitude == coordinate.latitude && marker.position.longitude == coordinate.longitude){
return marker;
}
NB this assumes that there is only one marker at this location.

Resources