This is a very simple question, but please help, because I am trying to solve these 3 days and I have no answer. I try many solutions, but again the same thing.
Here I have nArray functions that return me bigArray JSON that contain objects like this: bigArray
Array[5] 0: Object 1: Object DISTANCE_FROM_PREVIOUS_OBJECT_LOCATION: 2.087970147789207 lat: "48.866588" leftPosition: 183 lng: "2.309037999999987" topPosition: 57 __proto__: Object 2: Object 3: Object 4: Object length: 5 __proto__: Array[0]
So, I have an "n" number of objects. All objects contain lat and lng.
I am trying to solve my problem using the main Google example: http://jsfiddle.net/6Vz52/3/ but here I have a problem with how to change the <option value in the Google example with my JSON (lat, lng) data from mine code.
I am trying this code:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <script> var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); var chicago = new google.maps.LatLng(41.850033, -87.6500523); var mapOptions = { zoom:7, mapTypeId: google.maps.MapTypeId.ROADMAP, center: chicago } map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); directionsDisplay.setMap(map); } function calcRoute() { var start = document.getElementById('start').value; var end = document.getElementById('end').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); } }); } google.maps.event.addDomListener(window, 'load', initialize); </script>
but I donβt know where and how to place the JSON data (lat, lng) and draw several directions on the map.
How can I show directions on a map with coordinates in my objects?
UPDATE: google code doesn't have to be specified (you can put another google code code and integrate with my json), I just need a solution for direction based on my JSON array