I am really hoping someone can help me as I've been hitting my head against a wall for hours now.
A few weeks ago after trawling around various sites (mainly this one haha), I put together a bit of javascript that allowed a formidable pro database within a WordPress site to send its data to be geocoded with google and displayed on a map. It does this by passing the data into a variable using a php shortcode (nothing fancy), allowing me to specify the postcode and what text I want it to display when you click it.
Code Below:
var locations = [<?php echo FrmProDisplaysController::get_shortcode( array( 'id' => 21529, 'wpautop' => '0' ) ); ?>];
var mapOptions = {center: new google.maps.LatLng(51.5, -0.12),zoom: 10,mapTypeId: google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById('map'), mapOptions);
var infowindow = new google.maps.InfoWindow();var geocoder = new google.maps.Geocoder();
var bounds = new google.maps.LatLngBounds();
var marker, i;for (i = 0; i < locations.length; i++) {
codeAddress(locations[i]);
}
function codeAddress(location) {
geocoder.geocode({'address': location[1]}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
title: location[1],
position: results[0].geometry.location
});
bounds.extend(marker.getPosition());
map.fitBounds(bounds);
google.maps.event.addListener(marker, 'click', (function (marker, location) {
return function () {
infowindow.setContent(location[0]);
infowindow.open(map, marker);
};
})(marker, location));
}
});
}
Everything worked great...except the code I had got to work did not take into account the limits on the number of requests per second.
I've been looking around and found this excellent answer on here on how to fix the issue by Andrew Leach and have got this one to work also.
But this solution does not allow me to specify what text I want it to display for each entry.
I would really appreciate it if someone could help me adjust either code to solve either issue?
Thank you in advance for your time and effort.
All the best
Richard