Map Button Refresh Location

Map button refresh location

As @Orkhan said you can do it in this way.

If you want to do the action you just simple ctrl-drag to viewController and select "Action".

Sample Image

After that you can add code to the handler.

    var location: CLLocation!
@IBAction func refreshLocation(sender: AnyObject) {

let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

self.map.setRegion(region, animated: true)
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
self.location = locations.last as CLLocation
}

Update map location when clicking a button

You can simply move the map with map.setCenter(LatLng) under click event function. This method will not use any other markers and will not erase existing markers. You could also move the map via the panTo(LatLng) function. Both methods are also available after the map has been initialized.

$("#picadilly").click(function() {
lat = 53.4779168;
lng = -2.2338925;
map.setCenter({lat:lat , lng:lng});
});


$("#didsbury").click(function() {
lat = 53.410346;
lng = -2.229417;
map.setCenter({lat:lat , lng:lng});
});

Here is the documentation for these methods.

Android MapsActivity - onclick reload activity


What should I call instead of finish(); startActivity(getIntent()); to refresh map?

You can clear all the existing marker by invoking mMap.clear() and add the markers again according to new shared preference values.

Or

You can keep the references of your marker in arralist or something so that you can change their locations in map

Map refresh on button click-Javascript


$('button').on('click',initialize);

How to update a marker's location on google map without having to refresh entire map?

Your best bet is to use navigator.geolocation.watchPosition which calls a function only if the postion of the agent changes. So

1) you do not need to set a timer function to constantly refresh

2) the panning is handled by map.panTo() in this sample so that issue is addressed too.

3) the code below also uses the navigator.geolocation

<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>

Hope it all heped



Related Topics



Leave a reply



Submit