Ok I'm utterly confused. Google Maps API works FINE on local and live server, but not on my client's server. It throws the OVER_QUERY_LIMIT status, but it's NOT over the limit because it works fine on the other two servers when requesting from the url.
Here is my code to see what's going on:
function downloadUrl(url, callback) {
var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function searchLocationsNear() {
clearLocations();
var radius = document.getElementById('radius').value;
var category = document.getElementById('category').value;
var address = document.getElementById('address').value;
var searchURL = 'ajax/getPlaces.php?addr=' + address + '&rad=' + radius + '&cat=' + category;
downloadUrl(searchURL, function(data) {
var xml = parseXml(data);
var markerNodes = xml.documentElement.getElementsByTagName('marker');
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markerNodes.length; i++) {
var markerNum = i;
var id = markerNodes[i].getAttribute('id');
var logo = markerNodes[i].getAttribute('logo');
var city = markerNodes[i].getAttribute('city');
var state = markerNodes[i].getAttribute('state');
var zip = markerNodes[i].getAttribute('zip');
var phone = markerNodes[i].getAttribute('phone');
var email = markerNodes[i].getAttribute('email');
var web_link = markerNodes[i].getAttribute('web_link');
var name = markerNodes[i].getAttribute('name');
var address = markerNodes[i].getAttribute('address');
var distance = parseFloat(markerNodes[i].getAttribute('distance'));
var latlng = new google.maps.LatLng(parseFloat(markerNodes[i].getAttribute("lat")),parseFloat(markerNodes[i].getAttribute("lng")));
$( '#listings' ).append($('<div>').load( 'ajax/listingFind.php', {
id: id,
name: name,
logo: encodeURIComponent(logo),
address: address,
city: city,
state: state,
zip: zip,
phone: phone,
email: email,
web_link: encodeURIComponent(web_link),
distance: distance,
marker: markerNum
} ));
createMarker(latlng, name, address + '<br />' + city + ', ' + state + ' ' + zip);
bounds.extend(latlng);
fitToMarkers(bounds);
}
map.fitBounds(bounds);
$('.pag-borders').show();
});
}
getPlaces.php:
include_once('../../../app/scripts/config.php');
$googleMaps = new GoogleMaps();
$listingObject = new Listing();
$results = $googleMaps->get_places(trim($_GET['addr']), trim($_GET['rad']), array('category' => trim($_GET['cat']), 'status' => $listingObject->get_approved()));
$xml = $googleMaps->generate_xml($results);
echo $xml;
get_places method:
public function get_geocode($address) {
$request_url = 'http://maps.googleapis.com/maps/api/geocode/json' . '?address=' . urlencode($address) . '&sensor=' . $this->sensor;
$request = file_get_contents($request_url);
$response = json_decode($request, true);
if($response['status'] == 'OK') {
$geometry = $response['results'][0]['geometry'];
$this->lat = $geometry['location']['lat'];
$this->lng = $geometry['location']['lng'];
return true;
} else {
return false;
}
}
public function get_places($zip, $radius, array $args) {
$this->get_geocode($zip);
$this->select(array('id', 'name', 'address', 'city', 'state', 'zip', 'phone', 'email', 'web_link', 'user_id',
'logo', 'lng', 'lat', '( 3959 * acos( cos( radians('.$this->get_lat().') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('.$this->get_lng().') ) + sin( radians('.$this->get_lat().') ) * sin( radians( lat ) ) ) ) AS distance'));
$this->table($this->table);
if(count($args) > 0) {
$count = 0;
foreach($args as $key => $value) {
if($count == 0) {
$this->where($key, '=', $value);
} elseif($count > 0) {
$this->and_where($key, '=', $value);
}
$count++;
}
}
$this->having('distance', '<', $radius);
$this->order_by('distance');
$results = $this->all();
return $results;
}