Google Maps API适用于其他服务器,但不适用于主服务器
问题描述:
好的,我完全糊涂了。 Google Maps API在本地和实时服务器上运行FINE,但在我的客户端服务器上运行。它会抛出OVER_QUERY_LIMIT状态,但它没有超出限制,因为它在从URL请求时在其他两个服务器上正常工作。
这是我的代码,看看是什么继续:
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:
// Load PHP File
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);
}
/*
* Search locations near an address with a given radius and category
* @param address Address user types in (full or zip code)
* @param radius Radius drop down (25, 50, 75, etc)
* @param category Category drop down
*/
function searchLocationsNear() {
// clear current locations
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;
// generate xml and markup map
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++) {
// set keys with marker nodes to pass to view
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")));
// load view file
$( '#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:
getPlaces.php:
include_once('../../../app/scripts/config.php');
$googleMaps = new GoogleMaps();
$listingObject = new Listing();
// search places
$results = $googleMaps->get_places(trim($_GET['addr']), trim($_GET['rad']), array('category' => trim($_GET['cat']), 'status' => $listingObject->get_approved()));
// get xml
$xml = $googleMaps->generate_xml($results);
echo $xml;
get_places方法:
get_places method:
/*
* Sets geocode lat and lng
* @param address Street Address
* @param city City
* @param state State
* @param zip Zip
*/
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') {
// success
$geometry = $response['results'][0]['geometry'];
// Format:: Longitude, Latitude, Altitude
$this->lat = $geometry['location']['lat'];
$this->lng = $geometry['location']['lng'];
return true;
} else {
// fail
return false;
}
}
/*
* Get stores within mile radius of zip code
* @param zip Zip Code
* @param radius Mile Radius
* @param args Other arguments such as category drop down
*/
public function get_places($zip, $radius, array $args) {
// generate lat and lng for zip
$this->get_geocode($zip);
// start building query
$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);
// see if any additional args exist - no for loop since defined indexes in array reference database columns
if(count($args) > 0) {
// set your counter
$count = 0;
// loops through args
foreach($args as $key => $value) {
if($count == 0) {
$this->where($key, '=', $value);
} elseif($count > 0) {
$this->and_where($key, '=', $value);
}
$count++;
}
}
// finish query build
$this->having('distance', '<', $radius);
$this->order_by('distance');
$results = $this->all();
return $results;
}
答
(' #listings')。append(
( '#listings' ).append(
(' < div>')。load(' ajax / listingFind.php ',{
id:id,
name:name,
logo:encodeURIComponent(logo),
地址:地址,
city:city,
州:州,
zip:zip,
手机:手机,
电子邮件:电子邮件,
web_link:encodeURIComponent(web_link),
距离:距离,
marker:markerNum
}));
createMarker(latlng,name,address + ' < br />' + city + ' ,' +州+ ' ' + zip);
bounds.extend(latlng);
fitToMarkers(bounds);
}
map.fitBounds(bounds);
('<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-边界跨度>)表示();
});
}
('.pag-borders').show(); }); }
getPlaces.php:
getPlaces.php:
include_once('../../../app/scripts/config.php');