which marker is tapped in Google Maps SDK ios? - ios

I have many markers in GMSMapView. I want to know which marker is tapped.
I know that there is - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker delegate. But my problem is when i tap any marker, i will show different information for every marker in infoWindow. So, i must know which marker is tapped.How can i do this?

When you create the marker, set its userData property to an instance of your own class which stores data about the marker.
Then in didTapMarker, you can get out the userData property, cast it to your own type, and then extract the details you need.

You can set the accessibilityLabel property of marker during its creation from your data.
For example you are creating the markers from an array of objects then set the marker.accessibilityLabel of each marker as its position in your array so when user is going to tap on any marker, just find its accessibilityLabel and so find the data from array at this position.

Related

Google Maps Multiple Markers.How to get Particular marker id

I am implementing Google maps in my ios application where there are multiple Markers on it when a user taps I want to get the marker id so that I can take the data to the next screen. How can I achieve it
I have tried my luck in userdata and accessabilitylabel but when i tap on the same marker the id changes like first it prints 1 and then 2 if i tap on it again.
I want to get that Particular marker id am using array to show multiple markers.
Thanks in advance
when you tap on any marker
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(nonnull GMSMarker *)marker;
This Method called at that time.
You can get marker on Tap, you can check Position (marker.position.latitude,marker.position.longitude)
with your array and find the solution.

Google Maps IOS SDK - Refreshing the MapView. (Objective-c)

I made a settings tab for the MapView's ViewController and it works fine when I open the MapViews's VC the first time. but when I change the settings after I opened and loaded the mapView the first time the settings that I changed don't apply to the mapView because it did not refresh. Is there a way of refreshing the data of the mapView? I have searched everywhere and couldn't find an answer.
if this question have been answerd before can you link me to it? Thank you.
I'm using the GoogleMaps ios sdk.
and I'm using obj-c.
If your settings just changes the icons, annotations, map markers or layers color , or location of markers or layer, the simplest way to do is clear all the markers and layers you add on the map view and re-add them. For example, implement a refreshMapView method
-(void)refreshMapView
{
[mapView clear];//this line clears all the markers or layers you drew on the mapView.
// then implement your method to re-draw the markers and layers, or load new settings.
// for example, go through your marker list, and add them as follows:
for (id yourobject in yourMarkerArray){
GMSMarker *marker = [GMSMarker markerWithPosition:coordinatesOfMarker];
//custom marker here, set title, or snippets, or icon, etc...
marker.map = mapView;
}
// you can also redraw any map overlay here...
}
Jing's answer to implement a refreshMapView method is good, you could call that in your map view controller's viewWillAppear section.
Make sure you're actually setting the mapView properties in the same scope — i.e., your settings view and your map view may be looking at a different object or changes may be getting discarded. Without seeing the code for how you're trying to modify those settings, it's difficult to say.

How to drag marker in google maps

I am using google maps in my app. I am using a single marker. I want two things
When I tap on any location on map, My marker should animated to that position automatically. I am successful in this.
When I Long tap on the marker, it should animate up and move with my touch. when i release the touch, it should drag there.
I am having problem in the 2nd case. I have set the draggable property of the marker to true. Nothing else code is written . When i long tap on it, instead of the marker, whole map along with map moved up and then marker move acc to my touch. When i release the touch whole map along with marker move down slightly.
Any Suggestions Please?
In GMSMapDelegate, these are the methods related to dragging.
- (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker;
- (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker;
- (void)mapView:(GMSMapView *)mapView didDragMarker:(GMSMarker *)marker;
But you need to set marker draggable. By default, marker is not draggable.
marker.draggable=YES;
You have to press-and-hold on the marker before it will begin dragging.
I had also implemented this feature of dragable marker in google maps.
Now, according to your 2 point in question above, the up-down movement of map with marker on longpress and release, this is inbuilt feature of google maps library.
I think up-down movement of map along marker is to clearly show full marker to users when they long press o marker.
sometimes, marker icons are small which can be hidden by our fingers while long press and we can't see the marker to drag and place to another position.
To avoid this type of issue, google maps had added this feature.

Can I intercept marker deselect when I tap another marker in Google Maps SDK for iOS?

I know that I can use didTapAtCoordinate that will deselect the marker when I tap else where on the map.
But If there are multiple marker and I tap another one (Ex. MarkerA -> MarkerB), Is there any call back when the previous marker DidDeselect?.
I look around in GMSMapView the but can't find any thing I can use.
I want to change the marker color or image when it being selected and change it back when another marker select or the marker deselect.
Thank you.
The doco for selectedMarker says:
The marker that is selected. Setting this property selects a
particular marker, showing an info window on it. If this property is
non-nil, setting it to nil deselects the marker, hiding the info
window. This property is observable using KVO.
So, you could use Key Value Observing to be notified of changes to selectedMarker. If you use NSKeyValueObservingOptionOld when setting up KVO (described in more detail here), you will be notified of the old value, ie the marker which was deselected.

How to set draggable Map pin

I am developing an application in which I have included MapKit.
When first map is loaded at the time pin will be located at predefine place. And at that time drag-gable property of pin is set to NO.
Now I want to do this..
When user press button Edit it will allow user to drag pin. And when user drag pin and locate it at new place it will show user pin location name and lat long.
MKAnnotationView exposes the property draggable which can be set to enable dragging of each annotation added to map view.
The documentation for MKAnnotationView states:
If YES, the associated annotation object must also implement the setCoordinate: method. The default value of this property is NO.
Subclass MKAnnotationView and implement the setCoordinate method.
Then in your mapView:viewForAnnotation: method, set the draggable property to YES.

Resources