Reputation: 4451
In this case I needs to show at-least one marker and user location on map load. Is there any way to achieve that?
My approach is to get the nearest marker from user location and add it and current user location to fitToSuppliedMarkers
so it'll show user location and nearest marker and chnage zoom level according to that. any ideas?
Upvotes: 0
Views: 2818
Reputation: 2972
Try using animateToRegion()
, as said here.
Example:
zoomToLocation() {
let region = {
latitude: parseFloat(latitudeOfTheMarkerHere),
longitude: parseFloat(longitudeOfTheMarkerHere),
latitudeDelta: 5,
longitudeDelta: 5
};
let initialRegion = Object.assign({}, region);
initialRegion["latitudeDelta"] = 0.005;
initialRegion["longitudeDelta"] = 0.005;
this.mapView.animateToRegion(initialRegion, 2000);
}
Upvotes: 3