How to Refresh The Google Map in My Application Using Swift

How to Refresh the Google Map in my application using Swift?

First clear the all the mapView's previous markers with:

mapView.clear()

And then refresh your image array. Now again draw the markers for the refreshed array of images.

Refresh markers without refreshing entire Google map (Swift 2.0, Xcode v 7.0.1)

Yep, the map gets recreated every time you call:

let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.mapType = kGMSTypeNormal
mapView.myLocationEnabled = true
self.view = mapView

I'd suggest you instead set up the map view in interface builder instead, and just get a binding to it through IB's ability to add outlets to your class.

As to moving markers around, what you need to do is to hang on to the markers in a data structure in your code and move them, instead of attempting to recreate the display on each data refresh from the server.

Reloading Google Map View when adding and removing markers

First, if you just want the buttons to be layered on top of the map, just add the buttons to the view after you've added the map to the view; do not create a second view controller. Your problem is most likely caused by this awkward setup. You also don't have an @objc prefix in your action method, which would definitely prevent the button from executing its action.

@objc func updateButtons() {
mapView.clear() // clear the map
for i in someArray {
let marker = GMSMarker()
// configure parameters
marker.map = mapView
}
}

That method will update your map's markers. There is [probably] never a need to refresh the map, even if you want to change styles.

How to update Google Maps marker position in swift/iOS

If you have any kind of unique identifier for your positions that came from server, you can keep a list of markers and then update their location when new data arrive. Something like this:

for result in json.arrayValue {

let lat = result["latitude"].doubleValue
let lon = result["longitude"].doubleValue

let identifier = result["identifier"] as! String
self.myMarkersDictionary[identifier]?.position.latitude = lat
self.myMarkersDictionary[identifier]?.position.longitude = lon
...
}

How To Update Google Maps SDK iOS

You have to refresh cocoapod repo.

$sudo rm -fr ~/.cocoapods/repos/master
$pod setup

Cocoapod Setup may take some times to done.

$pod install

Auto reload map in Swift

Make sure that you declare that your view controller conforms to the GMSMapViewDelegate and that you set self.mapView.delegate = self in that view controller (usually in viewDidLoad).

Then add the rolling method in your view controller:

func mapView(mapView: GMSMapView!, didChangeCameraPosition position: GMSCameraPosition!) {
fetchNearbyPlaces(position.target)
}

How to update multiple location without clearing GoogleMap

you can subclass GMSMarker, add id of your objects, then get markers by object id you got from server and update position. Here is some code to explain what I mean

    class MyMarker: GMSMarker {

var id: String? = nil

}

add id to your marker

func setMarkers() {

let marker = MyMarker()
let friend = SharedData.sharedInstance.allFriends[I]
marker.id = friend.id

than update by id

for friend in SharedData.sharedInstance.allFriends {
guard
let marker = array.first { $0.id == friend.id }
else { contiunue }
marker.position = CLLocationCoordinate2D.init(latitude: friend.user_details.latitude , longitude: friend.user_details.longitude)
}

don't add marker to map again, just change it's position

Refresh the content within Google Maps iOS

I found the problem: I was allocating and initializing a whole new MapViewController each time the button was pressed

MapViewController *mapVC = [[MapViewController alloc]init];
[mapVC resetMap];

So i created a global variable, only allocated and initialized once in viewDidLoad, to use in my code



Related Topics



Leave a reply



Submit