本文介绍了谷歌地图超过查询限制,但有长和纬的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有坐标(Long& Lat),我使用PHP插入所有这些坐标,但我不知道如何更改javascript以纠正超出查询限制的错误。
这里是代码:
<!DOCTYPE html>
< html>
< head>
< meta charset =utf-8/>
< title>< / title>
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>< / script>
< script type =text / javascriptsrc =markerclusterer.js>< / script>
< script type =text / javascript>
var map;
//标记clusterer
var mc;
var mcOptions = {gridSize:20,maxZoom:17};
//全球infowindow
var infowindow =新google.maps.InfoWindow();
// geocoder
var geocoder = new google.maps.Geocoder();
var address = new Array(<?php echo(substr($ point_str,0,-2));?>);
var content = new Array(<?php echo(substr($ marker_str,0,-2));?>);
//乘数的最小和最大限制,对于随机数
//保持范围很小,所以标记保持靠近
var min = .999999;
var max = 1.000001;
函数createMarker(latlng,text){
///获取当前在集群中的标记数组
var allMarkers = mc.getMarkers();
//标记的最终位置,如果另一个标记已经存在于同一位置,则可以更新
var finalLatLng = latlng;
//检查是否有任何现有的标记符合新标记的位置
if(allMarkers.length!= 0){
for( i = 0; i< allMarkers.length; i ++){
var existingMarker = allMarkers [i];
var pos = existingMarker.getPosition();
//如果一个标记已经存在于这个标记的相同位置
if(latlng.equals(pos)){
//更新位置通过在其坐标上应用小倍数来重合标记
var newLat = latlng.lat()*(Math.random()*(max-min)+ min);
var newLng = latlng.lng()*(Math.random()*(max - min)+ min);
finalLatLng = new google.maps.LatLng(newLat,newLng);
$ b var marker = new google.maps.Marker({
position:finalLatLng
} );
google.maps.event.addListener(marker,'click',function(){
infowindow.close();
infowindow.setContent(text);
infowindow.open(map,marker);
});
返回标记;
函数geocodeAddress(address,i){
geocoder.geocode({'address':address},function(results,status){
if(status == google.maps.GeocoderStatus.OK)
{
var marker = createMarker(results [0] .geometry.location,content [i] ); mc.addMarker(marker);
}
else
{
alert(由于以下原因,Geocode不成功:+状态);
}
});
}
函数initialize(){
var options = {
zoom:4,
center:new google.maps.LatLng(39.8282, - 98.5795),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),options);
// marker marker
mc = new MarkerClusterer(map,[],mcOptions); (i = 0; i< address.length; i ++){
geocodeAddress(address [i],i);
。
}
}
< / script>
< style>
html,body,#map {
height:100%;
宽度:100%;
保证金:0;
padding:0;
}
< / style>
< / head>
< body onload ='initialize()'>
< div id =map>< / div>
< / body>
< / html>
这是HTML输出:
<!DOCTYPE html>
< html>
< head>
< meta charset =utf-8/>
< title>< / title>
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>< / script>
< script type =text / javascriptsrc =markerclusterer.js>< / script>
< script type =text / javascript>
var map;
//标记clusterer
var mc;
var mcOptions = {gridSize:20,maxZoom:17};
//全球infowindow
var infowindow =新google.maps.InfoWindow();
// geocoder
var geocoder = new google.maps.Geocoder();
var address = new Array(42.0619,-72.2136,
28.06,-81.9561,
30.3375,-81.7686,
30.3375, -81.7686,
41.7684,-88.1366,
28.06,-81.9561,
40.086,-82.486,
40.6278,-79.0896,
39.0197,-84.5914,
41.8119,-87.6873,
28.06,-81.9561,
42.8698,-85.9697,
42.8358, - 85.6644,
41.0309,-92.4098,
39.1024,-94.5986,
33.6115,-84.3745,
34.84,-115.967,
33.0807,-81.9868,
41.7369,-73.7411,
41.9214,-87.8924);
var unit = new Array(UnitNo1,
UnitNo2,
UnitNo3,
UnitNo4,
UnitNo5,
UnitNo6,
UnitNo7,
UnitNo8,
UnitNo9,
UnitNo10,
UnitNo11,
UnitNo12,
UnitNo13,
UnitNo14,
UnitNo15,
UnitNo16,
UnitNo17,
UnitNo18,
UnitNo19,
UnitNo20);
//乘数的最小和最大限制,对于随机数
//保持范围很小,所以标记保持靠近
var min = .999999;
var max = 1.000001;
函数createMarker(latlng,text){
///获取当前在集群中的标记数组
var allMarkers = mc.getMarkers();
//标记的最终位置,如果另一个标记已经存在于同一位置,则可以更新
var finalLatLng = latlng;
//检查是否有任何现有的标记符合新标记的位置
if(allMarkers.length!= 0){
for( i = 0; i< allMarkers.length; i ++){
var existingMarker = allMarkers [i];
var pos = existingMarker.getPosition();
//如果一个标记已经存在于这个标记的相同位置
if(latlng.equals(pos)){
//更新位置通过在其坐标上应用小倍数来重合标记
var newLat = latlng.lat()*(Math.random()*(max-min)+ min);
var newLng = latlng.lng()*(Math.random()*(max - min)+ min);
finalLatLng = new google.maps.LatLng(newLat,newLng);
$ b var marker = new google.maps.Marker({
position:finalLatLng
} );
google.maps.event.addListener(marker,'click',function(){
infowindow.close();
infowindow.setContent(text);
infowindow.open(map,marker);
});
返回标记;
函数geocodeAddress(address,i){
geocoder.geocode({'address':address},function(results,status){
if(status == google.maps.GeocoderStatus.OK)
{
var marker = createMarker(results [0] .geometry.location,content [i] ); mc.addMarker(marker);
}
else
{
alert(由于以下原因,Geocode不成功:+状态);
}
});
}
函数initialize(){
var options = {
zoom:4,
center:new google.maps.LatLng(39.8282, - 98.5795),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),options);
// marker marker
mc = new MarkerClusterer(map,[],mcOptions); (i = 0; i< address.length; i ++){
geocodeAddress(address [i],i);
。
}
}
< / script>
< style>
html,body,#map {
height:100%;
宽度:100%;
保证金:0;
padding:0;
}
< / style>
< / head>
< body onload ='initialize()'>
< div id =map>< / div>
< / body>
< / html>
谢谢!
解决方案
< html>
< head>
< meta charset =utf-8/>
< title>< / title>
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>< / script>
< script type =text / javascriptsrc =http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/src/markerclusterer.js><<< ; /脚本>
< script type =text / javascript>
var map;
//标记clusterer
var mc;
var mcOptions = {gridSize:20,maxZoom:17};
//全球infowindow
var infowindow =新google.maps.InfoWindow();
// geocoder
var geocoder = new google.maps.Geocoder();
var address = new Array(42.0619,-72.2136,
28.06,-81.9561,
30.3375,-81.7686,
30.3375, -81.7686,
41.7684,-88.1366,
28.06,-81.9561,
40.086,-82.486,
40.6278,-79.0896,
39.0197,-84.5914,
41.8119,-87.6873,
28.06,-81.9561,
42.8698,-85.9697,
42.8358, - 85.6644,
41.0309,-92.4098,
39.1024,-94.5986,
33.6115,-84.3745,
34.84,-115.967,
33.0807,-81.9868,
41.7369,-73.7411,
41.9214,-87.8924);
var unit = new Array(UnitNo1,
UnitNo2,
UnitNo3,
UnitNo4,
UnitNo5,
UnitNo6,
UnitNo7,
UnitNo8,
UnitNo9,
UnitNo10,
UnitNo11,
UnitNo12,
UnitNo13,
UnitNo14,
UnitNo15,
UnitNo16,
UnitNo17,
UnitNo18,
UnitNo19,
UnitNo20);
//乘数的最小和最大限制,对于随机数
//保持范围很小,所以标记保持靠近
var min = .999999;
var max = 1.000001;
函数createMarker(latlng,text){
var marker = new google.maps.Marker({
position:latlng,
map:map
});
google.maps.event.addListener(marker,'click',function(){
infowindow.close();
infowindow.setContent(text);
infowindow.open(map,marker);
});
返回标记;
}
函数initialize(){
var options = {
zoom:4,
center:new google.maps.LatLng(39.8282, - 98.5795),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),options);
var gmarkers = [];
for(i = 0; i< address.length; i ++){
var ptStr = address [i];
var coords = ptStr.split(,);
var latlng = new google.maps.LatLng(parseFloat(coords [0]),parseFloat(coords [1]));
gmarkers.push(createMarker(latlng,content [i]));
}
//标记群集
mc =新的MarkerClusterer(map,gmarkers,mcOptions);
}
< / script>
< style>
html,body,#map {
height:100%;
宽度:100%;
保证金:0;
padding:0;
}
< / style>
< / head>
< body onload ='initialize()'>
< div id =map>< / div>
< / body>
< / html>
如果您有经度和纬度的积分,请不要使用地理编码器。
;!DOCTYPE html>< html>
< head>
< meta charset =utf-8/>
< title>< / title>
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>< / script>
< script type =text / javascriptsrc =http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/src/markerclusterer.js><<< ; /脚本>
< script type =text / javascript>
var map;
//标记clusterer
var mc;
var mcOptions = {gridSize:20,maxZoom:17};
//全球infowindow
var infowindow =新google.maps.InfoWindow();
// geocoder
var geocoder = new google.maps.Geocoder();
var address = new Array(42.0619,-72.2136,
28.06,-81.9561,
30.3375,-81.7686,
30.3375, -81.7686,
41.7684,-88.1366,
28.06,-81.9561,
40.086,-82.486,
40.6278,-79.0896,
39.0197,-84.5914,
41.8119,-87.6873,
28.06,-81.9561,
42.8698,-85.9697,
42.8358, - 85.6644,
41.0309,-92.4098,
39.1024,-94.5986,
33.6115,-84.3745,
34.84,-115.967,
33.0807,-81.9868,
41.7369,-73.7411,
41.9214,-87.8924);
var unit = new Array(UnitNo1,
UnitNo2,
UnitNo3,
UnitNo4,
UnitNo5,
UnitNo6,
UnitNo7,
UnitNo8,
UnitNo9,
UnitNo10,
UnitNo11,
UnitNo12,
UnitNo13,
UnitNo14,
UnitNo15,
UnitNo16,
UnitNo17,
UnitNo18,
UnitNo19,
UnitNo20);
//乘数的最小和最大限制,对于随机数
//保持范围很小,所以标记保持靠近
var min = .999999;
var max = 1.000001;
函数createMarker(latlng,text){
var marker = new google.maps.Marker({
position:latlng,
map:map
});
google.maps.event.addListener(marker,'click',function(){
infowindow.close();
infowindow.setContent(text);
infowindow.open(map,marker);
});
返回标记;
}
函数initialize(){
var options = {
zoom:4,
center:new google.maps.LatLng(39.8282, - 98.5795),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),options);
var gmarkers = [];
for(i = 0; i< address.length; i ++){
var ptStr = address [i];
var coords = ptStr.split(,);
var latlng = new google.maps.LatLng(parseFloat(coords [0]),parseFloat(coords [1]));
gmarkers.push(createMarker(latlng,content [i]));
}
//标记群集
mc =新的MarkerClusterer(map,gmarkers,mcOptions);
}
< / script>
< style>
html,body,#map {
height:100%;
宽度:100%;
保证金:0;
padding:0;
}
< / style>
< / head>
< body onload ='initialize()'>
< div id =map>< / div>
< / body>
< / html>
I have the coordinates (Long & Lat) that I'm having PHP insert all of them but I don't know how to change the javascript to correct the over query limit error.
here is the code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="markerclusterer.js"></script>
<script type="text/javascript">
var map;
//marker clusterer
var mc;
var mcOptions = {gridSize: 20, maxZoom: 17};
//global infowindow
var infowindow = new google.maps.InfoWindow();
//geocoder
var geocoder = new google.maps.Geocoder();
var address = new Array(<?php echo(substr($point_str, 0, -2));?>);
var content = new Array(<?php echo(substr($marker_str, 0, -2));?>);
//min and max limits for multiplier, for random numbers
//keep the range pretty small, so markers are kept close by
var min = .999999;
var max = 1.000001;
function createMarker(latlng,text) {
///get array of markers currently in cluster
var allMarkers = mc.getMarkers();
//final position for marker, could be updated if another marker already exists in same position
var finalLatLng = latlng;
//check to see if any of the existing markers match the latlng of the new marker
if (allMarkers.length != 0) {
for (i=0; i < allMarkers.length; i++) {
var existingMarker = allMarkers[i];
var pos = existingMarker.getPosition();
//if a marker already exists in the same position as this marker
if (latlng.equals(pos)) {
//update the position of the coincident marker by applying a small multipler to its coordinates
var newLat = latlng.lat() * (Math.random() * (max - min) + min);
var newLng = latlng.lng() * (Math.random() * (max - min) + min);
finalLatLng = new google.maps.LatLng(newLat,newLng);
}
}
}
var marker = new google.maps.Marker({
position: finalLatLng
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.close();
infowindow.setContent(text);
infowindow.open(map,marker);
});
return marker;
}
function geocodeAddress(address,i) {
geocoder.geocode( {'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
var marker = createMarker(results[0].geometry.location,content[i]); mc.addMarker(marker);
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function initialize(){
var options = {
zoom: 4,
center: new google.maps.LatLng(39.8282,-98.5795),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
//marker cluster
mc = new MarkerClusterer(map, [], mcOptions);
for (i=0; i<address.length; i++) {
geocodeAddress(address[i],i);
}
}
</script>
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body onload='initialize()'>
<div id="map"></div>
</body>
</html>
This is the HTML OUTPUT:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="markerclusterer.js"></script>
<script type="text/javascript">
var map;
//marker clusterer
var mc;
var mcOptions = {gridSize: 20, maxZoom: 17};
//global infowindow
var infowindow = new google.maps.InfoWindow();
//geocoder
var geocoder = new google.maps.Geocoder();
var address = new Array("42.0619,-72.2136",
"28.06,-81.9561",
"30.3375,-81.7686",
"30.3375,-81.7686",
"41.7684,-88.1366",
"28.06,-81.9561",
"40.086,-82.486",
"40.6278,-79.0896",
"39.0197,-84.5914",
"41.8119,-87.6873",
"28.06,-81.9561",
"42.8698,-85.9697",
"42.8358,-85.6644",
"41.0309,-92.4098",
"39.1024,-94.5986",
"33.6115,-84.3745",
"34.84,-115.967",
"33.0807,-81.9868",
"41.7369,-73.7411",
"41.9214,-87.8924");
var content = new Array("UnitNo1",
"UnitNo2",
"UnitNo3",
"UnitNo4",
"UnitNo5",
"UnitNo6",
"UnitNo7",
"UnitNo8",
"UnitNo9",
"UnitNo10",
"UnitNo11",
"UnitNo12",
"UnitNo13",
"UnitNo14",
"UnitNo15",
"UnitNo16",
"UnitNo17",
"UnitNo18",
"UnitNo19",
"UnitNo20");
//min and max limits for multiplier, for random numbers
//keep the range pretty small, so markers are kept close by
var min = .999999;
var max = 1.000001;
function createMarker(latlng,text) {
///get array of markers currently in cluster
var allMarkers = mc.getMarkers();
//final position for marker, could be updated if another marker already exists in same position
var finalLatLng = latlng;
//check to see if any of the existing markers match the latlng of the new marker
if (allMarkers.length != 0) {
for (i=0; i < allMarkers.length; i++) {
var existingMarker = allMarkers[i];
var pos = existingMarker.getPosition();
//if a marker already exists in the same position as this marker
if (latlng.equals(pos)) {
//update the position of the coincident marker by applying a small multipler to its coordinates
var newLat = latlng.lat() * (Math.random() * (max - min) + min);
var newLng = latlng.lng() * (Math.random() * (max - min) + min);
finalLatLng = new google.maps.LatLng(newLat,newLng);
}
}
}
var marker = new google.maps.Marker({
position: finalLatLng
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.close();
infowindow.setContent(text);
infowindow.open(map,marker);
});
return marker;
}
function geocodeAddress(address,i) {
geocoder.geocode( {'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
var marker = createMarker(results[0].geometry.location,content[i]); mc.addMarker(marker);
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function initialize(){
var options = {
zoom: 4,
center: new google.maps.LatLng(39.8282,-98.5795),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
//marker cluster
mc = new MarkerClusterer(map, [], mcOptions);
for (i=0; i<address.length; i++) {
geocodeAddress(address[i],i);
}
}
</script>
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body onload='initialize()'>
<div id="map"></div>
</body>
</html>
Thank you!
解决方案
If you have the latitude and longitude for the points, don't use the geocoder.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/src/markerclusterer.js"></script>
<script type="text/javascript">
var map;
//marker clusterer
var mc;
var mcOptions = {gridSize: 20, maxZoom: 17};
//global infowindow
var infowindow = new google.maps.InfoWindow();
//geocoder
var geocoder = new google.maps.Geocoder();
var address = new Array("42.0619,-72.2136",
"28.06,-81.9561",
"30.3375,-81.7686",
"30.3375,-81.7686",
"41.7684,-88.1366",
"28.06,-81.9561",
"40.086,-82.486",
"40.6278,-79.0896",
"39.0197,-84.5914",
"41.8119,-87.6873",
"28.06,-81.9561",
"42.8698,-85.9697",
"42.8358,-85.6644",
"41.0309,-92.4098",
"39.1024,-94.5986",
"33.6115,-84.3745",
"34.84,-115.967",
"33.0807,-81.9868",
"41.7369,-73.7411",
"41.9214,-87.8924");
var content = new Array("UnitNo1",
"UnitNo2",
"UnitNo3",
"UnitNo4",
"UnitNo5",
"UnitNo6",
"UnitNo7",
"UnitNo8",
"UnitNo9",
"UnitNo10",
"UnitNo11",
"UnitNo12",
"UnitNo13",
"UnitNo14",
"UnitNo15",
"UnitNo16",
"UnitNo17",
"UnitNo18",
"UnitNo19",
"UnitNo20");
//min and max limits for multiplier, for random numbers
//keep the range pretty small, so markers are kept close by
var min = .999999;
var max = 1.000001;
function createMarker(latlng,text) {
var marker = new google.maps.Marker({
position: latlng,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.close();
infowindow.setContent(text);
infowindow.open(map,marker);
});
return marker;
}
function initialize(){
var options = {
zoom: 4,
center: new google.maps.LatLng(39.8282,-98.5795),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
var gmarkers = [];
for (i=0; i<address.length; i++) {
var ptStr = address[i];
var coords = ptStr.split(",");
var latlng = new google.maps.LatLng(parseFloat(coords[0]),parseFloat(coords[1]));
gmarkers.push(createMarker(latlng,content[i]));
}
//marker cluster
mc = new MarkerClusterer(map, gmarkers, mcOptions);
}
</script>
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body onload='initialize()'>
<div id="map"></div>
</body>
</html>
这篇关于谷歌地图超过查询限制,但有长和纬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 06:27