I am passing an array of address from my apex class. The addresses are coming over fine in JavaScript but I get an error mentioned below. The marker works fine when I hardcode the same address in the javascript.
ZERO_RESULTS
OVER_QUERY_LIMIT
Below is my VF PAGE
<apex:page showHeader="false" controller="GetRoute">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Maps API v3 Directions Example</title>
<script type="text/javascript" src="//maps.google.com/maps/api/js?key=AIzaSyAU45YYMFsnUGvJFTTcmxrP-dMTc3Eay9o&sensor=true"></script>
</head>
<body style="font-family: Arial; font-size: 12px;">
<apex:form id="theForm">
<apex:repeat value="{!addressList}" var="a">
The Text is {!a}
</apex:repeat>
<apex:inputhidden id="start" value="{!startpoint}" />
<apex:inputhidden id="end" value="{!endpoint}" />
</apex:form>
<div style="width: 100%;" id="mapDiv">
<div id="map" style="width: 70%; height: 600px; float: left;margin:0px;color:black;"></div>
<div id="panel" style="width: 30%; float: left;margin:0px;"></div>
</div>
<script type="text/javascript">
var myList = new Array();
myList = '{!addressList}'; // When myList is used , error is thrown
var addressArray = ["Aurangabad","Kolkata","Lucknow"]; //This works fine
console.log("========addressList======>" + addressArray);
var geocoder= new google.maps.Geocoder();
var markerBounds = new google.maps.LatLngBounds();
for (var i = 0; i < myList.length; i++) {
geocoder.geocode( { 'address': myList[i]}, function(results, status) { // when I replace mylist with addressArray, I dont get any error
console.log("=====City being processed====>"+addressArray[i]);
console.log("=====STATUS=====>"+status);
console.log("=====RESULTS=====>"+results);
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
markerBounds.extend(results[0].geometry.location);
map.fitBounds(markerBounds);
} else {
//alert("Geocode was not successful for the following reason: " + status);
}
});
}
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 0,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('panel'));
var request = {
origin: document.getElementById("{!$Component.theForm.start}").value,
destination: document.getElementById("{!$Component.theForm.end}").value,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
ex = document.getElementById("{!$Component.theForm.start}").value;
console.log("====start point is ===>" + ex);
console.log("=====ReSPONSE IS ======>" + response);
directionsDisplay.setDirections(response);
}
});
</script>
</body>
Below is my APEX Class
public with sharing class GetRoute {
public static List<String> addressList{get;set;}
public GetRoute(){
addressList = new List<String>();
addressList.add('Pune');
addressList.add('Indore');
addressList.add('Lucknow');
addressList.add('Delhi');
}
Below is a snapshot of the address in console. Seems same to me.
I am getting mixed result in console and the tags are showing in wrong country.