Utilizing the Google Maps Javascript API V3 in my Android WebView has presented a new issue. When I request directions from point A to B, it displays correctly. However, when I switch the endpoints to go from A to C, the route from A to B does not disappear and ends up overlapping with the newly generated route from A to C.
A to B
A to C
Button to proceed with directions
direction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
button.setVisibility(View.INVISIBLE);
infowindow.setVisibility(View.INVISIBLE);
String centerUrl = "javascript:direction(" + Lat + "," + Lng + "," + LatNew + "," + LngNew + ")";
webView.loadUrl(centerUrl);
}
});
HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var myLatLng,endLatLng;
var map;
var marker,beachMarker,eatMarker,drinkMarker;
var location;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 17,
center: myLatLng
});
// Marker initialization code continues here...
}
// Additional functions like centerAt and direction continue as before...
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&callback=initMap"></script>
How can I remove the old route display when changing destination points?