[英]google maps drag ajax not working
我正在尝试获取类似http://www.yelp.com/的功能,当用户拖动地图时,它将调用ajax并收集纬度,经度和填充地图标记。
这是我尝试过的一些示例代码
function initialize() {
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng(32.1594, -80.7614),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('mymap-screenwrap'), mapOptions);
google.maps.event.addListener(map, 'dragend', getPinsToMapBound);
google.maps.event.addListener(map, 'zoom_changed', getPinsToMapBound);
var start =(document.getElementById('cr-start-point'));
var end=(document.getElementById('cr-end-point'));
var autocompleteA = new google.maps.places.Autocomplete(start);
var autocompleteB = new google.maps.places.Autocomplete(end);
directionsDisplay.setMap(map);
directionsDisplay.setOptions( { suppressMarkers: true } );
directionsDisplay.setPanel(document.getElementById('panel-direction-content'));
if(start.value != '') {
routehelper();
}
}
function getPinsToMapBound(ev) {
var ids;
if(ids = $$('.mymaps_topmenu a.pressed').get('id')) {
var bounds = map.getBounds();
var ne = [bounds.getNorthEast().lat(), bounds.getNorthEast().lng()];
var sw = [bounds.getSouthWest().lat(), bounds.getSouthWest().lng()];
jQuery.ajax({
url: '/rvillage/maps/get-data-within-lat-lng',
data: {bounds : bounds, ne : ne, sw : sw, format : 'json'},
dataType: 'json'
}).done(function( data ) {
console.log(data);
});
}
}
现在的问题是,当我拖动地图时,ajax部分不起作用,它会引发错误-TypeError:这是未定义的https://maps.gstatic.com/cat_js/intl/en_us/mapfiles/api-3/16/3/ %7Bmain,places%7D.js第28行 。 如果我关闭Ajax,则不会引发错误。 谁能指出我做错了什么? 我同时使用了mootools和jQuery,并且在评论ajax part时没有错误,并且我已经使用mootools delay来延迟此功能,但是没有用 。 提前致谢。
这是一个愚蠢的错误,我将bounce
值阿贾克斯数据,是创造问题,因为当它被调用toString
的bounce
值错误发生在bounce
值是没有必要的
function initialize() {
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng(32.1594, -80.7614),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('mymap-screenwrap'), mapOptions);
google.maps.event.addListener(map, 'dragend', getPinsToMapBound);
google.maps.event.addListener(map, 'zoom_changed', getPinsToMapBound);
var start =(document.getElementById('cr-start-point'));
var end=(document.getElementById('cr-end-point'));
var autocompleteA = new google.maps.places.Autocomplete(start);
var autocompleteB = new google.maps.places.Autocomplete(end);
directionsDisplay.setMap(map);
directionsDisplay.setOptions( { suppressMarkers: true } );
directionsDisplay.setPanel(document.getElementById('panel-direction-content'));
if(start.value != '') {
routehelper();
}
}
function getPinsToMapBound(ev) {
var ids;
if(ids = $$('.mymaps_topmenu a.pressed').get('id')) {
var bounds = map.getBounds();
var ne = [bounds.getNorthEast().lat(), bounds.getNorthEast().lng()];
var sw = [bounds.getSouthWest().lat(), bounds.getSouthWest().lng()];
jQuery.ajax({
url: '/rvillage/maps/get-data-within-lat-lng',
data: {ids : ids, ne : ne, sw : sw, format : 'json'},//removed bounds as it wasn't needed
dataType: 'json'
}).done(function( data ) {
console.log(data);
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.