Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

iphone - Change Google Maps' Selected Marker or change marker's color? [iOS]

I am wondering if there is a way to change the color or image of the selected marker and then change it back when it is not selected anymore. I see that Yelp, which uses Apple Maps, changes the color/image of the selected marker and then back to the original once that one is no longer selected and was wondering if the Google Map iOS SDK had something similar or if someone has come across this problem and found a solution.

What I have tried:

I have looked through Google's Documentation on Markers (found here) and see that they have marker.opacity which changes the opacity and marker.icon = [GMSMarker markerImageWithColor:[UIColor blackColor]]; which changes the marker's color.

I have tried to manually change it in -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker; by adding this line marker.icon = [GMSMarker markerImageWithColor: [UIColor differentColor]]; or this line marker.icon = [UIImage imageNamed:@"differentColorImage"]; but when you tap out of the marker/info-window, the image/color remains the same.

Anyone have any thoughts? Anything helps. Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To change icon of marker that selected and for not selected what i did was, First I add all the GMSMarker in an array.After that inside delegate function didTapMarker: I got selected marker and change the icon of that marker

     - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
       {
         marker.icon=[UIImage imageNamed:@"selectedicon.png"];//selected marker

           for (int i=0; i<[markerArray count]; i++) 
            {
             GMSMarker *unselectedMarker=markerArray[i];
        //check selected marker and unselected marker position
             if(unselectedMarker.position.latitude!=marker.position.latitude &&    unselectedMarker.position.longitude!=marker.position.longitude)
            {
                unselectedMarker.icon=[UIImage imageNamed:@"unselectedicon.png"];
            } 
          }


         return NO;
       }

This is working for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...