1
我正在研究屬性搜索系統的API,並試圖讓屬性在Google地圖上顯示爲標記。一切工作正常與API,我得到有效的答覆,正是我正在尋找和我期望得到的。我遇到的問題是標記。Google Maps API不顯示所有標記
我限制了對100個屬性的響應,並要求他們具有要進行地理編碼的信息。我獲得了100個屬性,可以遍歷並列出所有屬性,但我在地圖上最多隻能獲得11個標記。根本不改變標準並再次搜索應該返回相同的結果,但我得到了一組不同的標記。再次搜索,我得到一個標記。
我也遇到了標記變量的問題。我在載入時將它設置爲一個空數組,然後將每個屬性的標記推送給它,但是當我控制檯記錄數組時,它總是空的。
這裏就是整個的javascript:
<script>
var user = "bac0Fmk5";
var key = "Vkjx5BV8VeYOxAixFD";
var secret = "CU5g6wQR2ZJV7";
var markers = [];
$(document).ready(function(){
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(30.1767, -85.8056),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var geocoder = new google.maps.Geocoder();
var infowindow = new google.maps.InfoWindow({
content: ''
});
$('#search_btn').click(function(){
clearOverlays();
$.ajax({
type: 'POST',
dataType: "json",
async: false,
url: "api/ex.api.php",
data: {
user: user,
key: key,
secret: secret,
area: $('#area').val(),
category: $('#type').val(),
min_price: $('#min_price').val(),
max_price: $('#max_price').val(),
bedrooms: $('#bedrooms').val(),
bathrooms: $('#bathrooms').val(),
subdivision: $('#subdivision').val(),
city: $('#city').val(),
mls_acct: $('#mls_acct').val()
},
success: function (responseData, textStatus, jqXHR) {
// console.log(responseData);
// console.log(jqXHR);
$.each(jqXHR.responseJSON, function(i, e){
//console.log(e.mls_acct);
geocoder.geocode({ 'address': e.street_num+' '+e.street_name+' '+e.city+','+e.state+' '+e.zip}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// console.log("location : " + results[0].geometry.location.lat() + " " +results[0].geometry.location.lng());
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
//window.locs.push([lat, lng]);
if(e.street_num == '' || e.street_name == '' || e.city == '' || e.state == '' || e.zip == '')
{
console.log('got a dead one');
}
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map
});
markers.push(marker);
bindInfoWindow(marker, map, infowindow, "<div><h2>"+e.mls_acct+"</h2></div>");
}
});
});
},
error: function (responseData, textStatus, errorThrown) {
console.log('Response Data: ' + responseData);
console.log('Status: ' + textStatus);
console.log('Error Thrown: ' + errorThrown);
}
});
return false;
});
});
function bindInfoWindow(marker, map, infowindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(html);
infowindow.open(map, marker);
});
}
function clearOverlays() {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
markers.length = 0;
}
</script>
可能重複:// stackoverflow.com/questions/21422125/google-maps-on-my-visual-force-page-doesnt-show-all-markers-as-the-number-of-re) – geocodezip