0
Good night! I’m developing a web page where the user can plot a route. I use the google maps api. I need to take the latitude and longitude pairs of the route, press for an object c# and, after working the latitude and longitude information, return the lat. e long. for google maps to color the route according to the information I will return. For example: when I return latitude: -12.123, longitude: 13.123 I need it to be colored according to a weight I will pass. For example, if the weight is less than 5, then color yellow, greater than 5, blue. I will post my code that generates the route for who knows you help me.
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script language="javascript" type="text/javascript">
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function InitializeMap() {
directionsDisplay = new google.maps.DirectionsRenderer();
var latlng = new google.maps.LatLng(-19.9412735, -44.07623219999999);
var myOptions =
{
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directionpanel'));
var control = document.getElementById('control');
control.style.display = 'block';
}
function calcRoute() {
var start = document.getElementById('startvalue').value;
var end = document.getElementById('endvalue').value;
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function Button1_onclick() {
calcRoute();
}
window.onload = InitializeMap;
</script>
Gypsy, thanks for the help, but I have little knowledge of Java and C#, so I still have difficulties to solve my problem, because I need to get the coordinates of the route and, before generating the route to the user, I work the information and, according to the result of what I do, then I need to plot the route with different colors in each stretch according to a value. I am not making progress in this direction, could you give me a help with this problem, or give me a material or example on the web even if it is similar? Thank you so much!
– Géberson Rogério Cardoso
I confess that I do not know well the Google Maps API, but in theory your code works. I found this link that can help.
– Leonel Sanches da Silva
I’m studying it and it seems it will help me. Thank you very much Gypsy.
– Géberson Rogério Cardoso