I try to remove specified marker in IOS it does not work but only work in markers.clear(). I tried to this issue in android phone, working fine. Can you solve this problem.
Marker marker1 = markers.firstWhere((marker) => marker.markerId.value == 'Add_Photo_1',);
Marker marker2 = markers.firstWhere((marker) => marker.markerId.value == '2',);
setState(() {
markers.remove(marker1);
markers.remove(marker2);
});
Related
I am using capacitor geolocation plugin to find current location coordinates(latitude and longitude).
const coordinates = await Geolocation.getCurrentPosition({enableHighAccuracy:true});
const center = {lat: coordinates.coords.latitude, lng: coordinates.coords.longitude};
But in Iphone its taking around 45sec to 1.5 mins to fetch current location.
I have also used below code. But this is sometime fast sometime slow.
const id = await Geolocation.watchPosition({}, (coordinates, err) => {
Geolocation.clearWatch({id});
if(err) {
console.log(err)
}
console.log('getCenter ios',coordinates);
const center = {lat: coordinates.coords.latitude,
lng:coordinates.coords.longitude};
});
Is there any other implementation or free/paid plugin available, which can fetch current location coordinates faster on iphone.
I'm using "react-native-maps": "0.29.4", and google provider on the Map component.
for some reason, using animateCamera on ios only and only in some cases (mainly after refreshing the app as in switching rtl to ltr for example either after initial getting user location GPS permission) has an offset that what supposed to be on the center going to the top left corner
https://youtu.be/3cLeZSIAaVk
the video shows the bag while using handlePressMyLocation function
const handleAnmiateToRegion = useCallback((center: IMapLocation, zoom: number = undefined) => {
mapRef.current
? mapRef.current.animateCamera({ center, zoom })
: setTimeout(() => {
handleAnmiateToRegion(center, zoom)
}, 100)
}, [])
const handlePressMyLocation = useCallback(() => {
handleAnmiateToRegion(location)
}, [location.latitude, location.longitude])
again, this is never happening on android, and also on ios sometimes it's working normally, but in case a session has this bug, it gonna happen all the time and in all of animateCamera usage (there're more cases for this handleAnmiateToRegion as init focusing + zooming or in case of pressing some of the markers)
any thoughts? also tried to change animateCamera to animateToRegion, as well as calling the functions with 12 digits after . instead of 5 (as given by Geolocation.watchPosition) but the same bug occurs)
thanks in advance!
(in case more code will help, pls write in a comment and I'll add)
For some reason, rendering the map only after I got the user location (using memo for making sure it indeed happen and for avoiding unnessecary rerendering) and setting initialRegion prop on Map fixed the issue
<MapView
provider={PROVIDER_GOOGLE}
key={this.state.forceRefresh}
style={styles.gmapView}
showsUserLocation
ref={(ref) => (this.mapView = ref)}
followUserLocation
showsMyLocationButton
snappedminZoomLevel={Platform.OS == "ios" ? this.state.zoom : 12}
/* minZoomLevel={11}
maxZoomLevel={17} */
showsMyLocationButton={false}
initialRegion={{
latitude: latlong.lat || currentLocation.latitude,
longitude: latlong.lng || currentLocation.longitude,
latitudeDelta: this.state.latitudeDelta,
longitudeDelta: this.state.longitudeDelta,
}}
onRegionChange={(data) =>
this.setState(
{
newLatitude: data.latitude,
newLongitude: data.longitude,
zoom:Math.round(Math.log(360 / data.longitudeDelta) / Math.LN10),
latitudeDelta: data.latitudeDelta,
longitudeDelta: data.longitudeDelta,
},
() => {
console.log("data ==> "+JSON.stringify(data))
}
)
}
onPress={(e) =>{
this.animate(e)
}
}
>
</MapView>
animate(e){
let lat = e?.nativeEvent?.coordinate?.latitude + 0.004000;
let long = e?.nativeEvent?.coordinate?.longitude - 0.004000;
let r = {
latitude: lat,
longitude: long,
latitudeDelta: 0.38,//this.state.latitudeDelta,
longitudeDelta: 0.28,//this.state.longitudeDelta,
};
this.mapView.animateToRegion(r, 300);}
can you try this? may be it's helping you
My app is loading a HERE map, and works fine with a set of manually entered coordinates as the centre point.
I have implemented Geolocator in another part of the app to produce the users location which is then implemented into a function to find places near their current location & display on map.
I have now taken the Geolocator position finder and want to use it to open the map on the users location. The code uses async and await to get users coordinates.
The map open function does not want to accept async/ await, yet I have tried building it within its own class and pulling the coords, without success.
I am relatively new and any advice is greatly appreciated
Async & Await are currently red underlined in the 'function to open map', and when I change MapMarkerExample to mapMarkerExample at the top of 'function to open map', _mapMarkerExample = MapMarkerExample (_showDialog, hereMapController); is red underlined on `command to open map'
Command to open map
void _onMapCreated(HereMapController hereMapController) {
hereMapController.mapScene.loadSceneForMapScheme(MapScheme.normalDay, (MapError error) {
if (error == null) {
_mapMarkerExample = MapMarkerExample (_showDialog, hereMapController);
} else {
print("Map scene not loaded. MapError: " + error.toString());
}
});
}
Function to open map
MapMarkerExample(ShowDialogFunction showDialogCallback, HereMapController hereMapController) async {
_showDialog = showDialogCallback;
_hereMapController = hereMapController;
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
var lat = position.latitude;
var long = position.longitude;
double distanceToEarthInMeters = 8000;
_hereMapController.camera.lookAtPointWithDistance(
GeoCoordinates(lat, long), distanceToEarthInMeters);
_setTapGestureHandler();
_showDialog("Note", "Tap markers for more.");
}
The problem is that MapMarkerExample() is a constructor and constructors cannot be executed asynchronously.
One possible way to solve this is to not set the coords in the MapMarkerExample() constructor. Just call it to create the instance. And then in a second method _setMapTarget() you can set the center coords of the map.
_setMapTarget() is marked async, so it will be executed immediately and it will not block _onMapCreated(). But it will do the magic a little bit later, fetch the position and once it has the position, it will update the camera.
If fetching the position takes to long, then you would see for that time a default camera position of the map.
void _onMapCreated(HereMapController hereMapController) {
hereMapController.mapScene.loadSceneForMapScheme(MapScheme.normalDay, (MapError? error) {
if (error == null) {
_mapMarkerExample = MapMarkerExample(_showDialog, hereMapController);
_setMapTarget(hereMapController);
} else {
print("Map scene not loaded. MapError: " + error.toString());
}
});
}
Future<void> _setMapTarget(HereMapController hereMapController) async {
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
var lat = position.latitude;
var long = position.longitude;
double distanceToEarthInMeters = 8000;
hereMapController.camera.lookAtPointWithDistance(GeoCoordinates(lat, long), distanceToEarthInMeters);
}
I want to hide the marker after the zoom level reach 17, someone suggested I use clear method, but the issue with it that I have different marker that will show after some event so clear is not going to work any idea how can I made this possible?
To remove a specific marker
myMarker.map = nil
as far as I know there are no definite references to hiding markers, but you can manipulate marker data displayed on the map #CMIIW
as an example
var markers: [GMSMarker] = []
var tempMarker: [GMSMarker] = []
if zoom == 17 {
// TODO: Create tempMarker filter from markers
} else {
// TODO: Create tempMarker filter from markers
}
// TODO:
// mapView.clear()
// Mapview show markers from tempMarker
iOS Swift Google Maps SDK showing markers at specific zoom level?
//To delete
marker.map = nil
//to hide
marker.opacity = 0.0
Hi just learn to use react-native and javascript. How do I placed multiple markers on react-native map?
Just push more data into the marker and setstate to marker and assign to
annotations={this.state.marker}
var tempMarker = [];
for (var p in responseData) {
tempMarker.push({
latitude: region.latitude,
longitude: region.longitude
})
}
this.setState({
marker: tempMarker
})