谷歌地图 API v3
我想在地图上绘制大约 500-600 个图钉。我收到 OVER_QUERY_LIMIT 错误。如果我将数据库中的地址手动地理编码为纬度/经度,这有关系吗?这是一种避免每天 2500 个查询限制的方法,因为不会进行经纬度转换的地址吗?
这是我使用的代码
块引用
<script src="http://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js" type="text/javascript"></script>
<style type="text/css"> #ppt-object-map { height:<?php echo $h; ?>px; width:<?php echo $w; ?>px; }</style>
<script type="text/javascript">
function initialize() {
var myOptions = { zoom: <?php echo get_option("ppt_object_map_zoom"); ?>, center: new google.maps.LatLng(44.69,-63.62), mapTypeId: google.maps.MapTypeId.ROADMAP }
var map = new google.maps.Map(document.getElementById("ppt-object-map"), myOptions); setMarkers(map, featuredlistings);
}
var featuredlistings = [
<?php
if(!empty($postslist)){ $i=1;
foreach($postslist as $post){
$map = trim(strip_tags((get_post_meta($post->ID, 'map_location', true))));
if(strlen($map) > 5){
echo "['".addslashes(str_replace("-"," ",$post->post_title)).premiumpress_image($post- >ID,"",array('alt' => $post->post_title, 'link' => true, 'width' => '120', 'height' => '100', 'style' => 'auto' ))."', '".get_post_meta($post->ID, 'map_location', true)."', ".$i."],"; $i++; } } }
?>
];
function setMarkers(map, locations) {
for (var i = 0; i < locations.length; i++) {
var featuredlistings = locations[i];
DrawIcon(map,featuredlistings);
}
}
function DrawIcon(map,featuredlistings){
var image = new google.maps.MarkerImage('<?php echo PPT_FW_JS_URI; ?>/map/icon.png',
new google.maps.Size(20, 32),
new google.maps.Point(0,0),
new google.maps.Point(0, 32));
var shadow = new google.maps.MarkerImage('<?php echo PPT_FW_JS_URI; ?>/map/shadow.png',
new google.maps.Size(37, 32),
new google.maps.Point(0,0),
new google.maps.Point(0, 32));
var image = "<?php echo PPT_FW_JS_URI; ?>map/iconx.png";
var shadow = "<?php echo PPT_FW_JS_URI; ?>map/shadow.png";
var shape = {
coord: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': featuredlistings[1] }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
shadow: shadow,
icon: image,
map: map,
position: results[0].geometry.location,
});
var boxText = document.createElement("div");
if(featuredlistings[0].length > 20){
var maph = -80;
var mapw = -160
boxText.style.cssText = "margin-top: 8px; background: #000000; padding: 5px; -moz- border-radius: 3px; border-radius: 3px; font-size:12px; font-weight:bold; color:#fff; padding-bottom:10px;";
} else{
var maph = -80;
var mapw = -70
boxText.style.cssText = "margin-top: 8px; background: #000000; padding: 5px; -moz- border-radius: 3px; border-radius: 3px; font-size:12px; font-weight:bold; color:#fff;";
}
boxText.innerHTML = "<div class='map_container'>"+featuredlistings[0]+"</div>";
var myOptions = {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(maph, mapw)
,zIndex: null
,boxStyle: {
opacity: 0.8
,width: "160px"
}
,closeBoxMargin: "10px 2px 2px 2px"
,closeBoxURL: "<?php echo PPT_FW_JS_URI; ?>/map/close.png"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: true
};
google.maps.event.addListener(marker, 'mouseover', function(e) { ib.open(map, marker); });
google.maps.event.addListener(marker, "click", function (e) { ib.open(map, this); });
var ib = new InfoBox(myOptions);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}