简体   繁体   中英

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 — ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM