setPoints not behaving as expected
I'm submitting a ... (check one with "x")
- [ ] question
- [X] any problem or bug report
- [ ] feature request
If you choose 'problem or bug report', please select OS: (check one with "x")
- [ ] Android
- [x] iOS
cordova information: (run $> cordova plugin list)
com.googlemaps.ios 2.7.0 "Google Maps SDK for iOS"
com.testfairy.cordova-plugin 2.13.0 "TestFairy Plugin"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-crosswalk-webview 2.4.0 "Crosswalk WebView Engine"
cordova-plugin-device 1.1.7 "Device"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-googlemaps 2.3.6 "cordova-plugin-googlemaps"
cordova-plugin-insomnia 4.3.0 "Insomnia (prevent screen sleep)"
cordova-plugin-mauron85-background-geolocation 2.3.5 "CDVBackgroundGeolocation"
cordova-plugin-network-information 1.3.4 "Network Information"
cordova-plugin-splashscreen 4.1.0 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-sqlite-storage 2.3.3 "Cordova sqlite storage plugin"
ionic-plugin-deploy 0.6.7 "IonicDeploy"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-barcodescanner 6.0.8 "BarcodeScanner"
phonegap-plugin-push 1.11.1 "PushPlugin"
If you use @ionic-native/google-maps, please tell the package.json (only @ionic-native/core and @ionic-native/google-maps are fine mostly)
"@ionic-native/google-maps": "^4.8.2",
Current behavior: In the code below we create a map, get the location and calculate a route to the destination. We then trigger the geolocation watch position so that when the handset moves we can update the route polyline.
Expected behavior: When we call setPoints with the new routes array, we are expecting the polyline to update. I.e get shorter the closer we get to the destination. However, the polyline just stays as it was originally drawn and never seems to update correctly.
Related code, data or error log (please format your code or data):
let mapDiv = document.getElementById("map");
let map = plugin.google.maps.Map.getMap(mapDiv, {
backgroundColor: 'white',
controls: {
compass: false,
myLocationButton: false,
indoorPicker: true,
zoom: true
},
gestures: {
scroll: true,
tilt: true,
rotate: true,
zoom: true
},
camera: {
target: this.currentPositionLatLng,
tilt: 30,
zoom: 15,
bearing: 0
}
});
map.one(plugin.google.maps.event.MAP_READY, onMapInit);
function onMapInit(map) {
map.setMyLocationEnabled(true);
let currentPosition = new LatLng(-25.990733, 28.050910);
let destination = new LatLng(-25.977923, 28.115341);
let route = [];
let directionsService = new google.maps.DirectionsService();
directionsService.route(
{
origin: currentPosition,
destination: destination,
travelMode: google.maps.TravelMode.DRIVING
},
(res, status) => {
if (status == google.maps.DirectionsStatus.OK) {
// Loop through each direction route point and add it to be plotted
for (let i = 0, len = res.routes[0].overview_path.length; i < len; i++) {
let point = res.routes[0].overview_path[i],
latLng = new LatLng(point.lat(), point.lng());
route.push(latLng);
}
// now that we have a route, lets draw and start to watch
let polyline = map.addPolyline({
color: '#4986E7',
visible: true,
width: 7,
points: route
});
let watchPositionSubscription = navigator.geolocation.watchPosition(function(position){
console.log('position callback', position);
// reset route points
route = [];
directionsService.route(
{
origin: new LatLng(position.coords.latitude, position.coords.longitude),
destination: destination,
travelMode: google.maps.TravelMode.DRIVING
},
function(res, status){
if (status == google.maps.DirectionsStatus.OK) {
// Loop through each direction route point and add it to be plotted
for (let i = 0, len = res.routes[0].overview_path.length; i < len; i++) {
let point = res.routes[0].overview_path[i],
latLng = new LatLng(point.lat(), point.lng());
route.push(latLng);
}
console.log('updating polyline');
polyline.setPoints(route);
} else {
console.log('google.maps.DirectionsStatus.ERROR', status);
}
}
);
}, function(error){
console.log(error);
}, {
enableHighAccuracy: true
});
} else {
console.log('google.maps.DirectionsStatus.ERROR', status);
}
}
);
}
Please create a project that reproduce your issue 100%.
For example, there is a map and a button, and there is a path on the map. After clicking a button, update the path with dummy data. So the issue should be reproduce 100%.
ping
I'll have to put an app together. I have narrowed it down to IOS only issue. setPoints() works as intended on Android using the exact code as per above but not on ios.
I'll get a basic project up shortly
here is a very simple working ionic project, https://github.com/ratt/maps-example. In short, each button simulates shortening of the route polyline. Expected behavior the ployline should redraw i.e get shorter. Andriod this works as expected but on ios the ployline does not change.
Thanks. I will check it today.
Sorry for late. The bug is fixed. Please reinstall the plugin from the multiple_maps branch.
