Javascript 列表中的单选按钮,由填充。每个循环
嗨,我是谷歌地图和Jquery的新手,我遇到了一个问题,当单选按钮改变时,我需要触发或聚焦来设置地图焦点。有人能帮我解决这种情况吗 代码段:Javascript 列表中的单选按钮,由填充。每个循环,javascript,jquery,html,google-maps,google-maps-api-3,Javascript,Jquery,Html,Google Maps,Google Maps Api 3,嗨,我是谷歌地图和Jquery的新手,我遇到了一个问题,当单选按钮改变时,我需要触发或聚焦来设置地图焦点。有人能帮我解决这种情况吗 代码段: function initialize() { var minZoomLevel = 4; var zooms = 7; geocoder = new google.maps.Geocoder(); geocode = new google.maps.Geoco
function initialize() {
var minZoomLevel = 4;
var zooms = 7;
geocoder = new google.maps.Geocoder();
geocode = new google.maps.Geocoder();
// Used to Set the Center of the Maps on the Logged User
$.getJSON('/Dashboard/LoadAddress', function Geocoding(address) {
$.each(address, function () {
customerlocationID = this["ID"];
var currValAddress = this["AddressLine1"];
var Latitude = this["Latitude"];
var Longitude = this["Longitude"];
LatLang = new google.maps.LatLng(Latitude, Longitude);
var addresse = {
zoom: 16,
center: LatLang,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), addresse);
var link = $('<input type="radio" name="a"/><label>'+ currValAddress+'</label>').data('location', LatLang);
$('#initialPlace').append($('<li id=\'List\' class=\'List\'>').append(link));
link.on('click', function (event) {
var $t = $(event.target);
if ($t.hasClass('checked')) {
map.setCenter(LatLang);
$t.removeAttr('checked');
}
$('input[type="radio"][name="' + $t.prop('name') + '"]').not($t).removeClass('checked');
$t.toggleClass('checked');
}).filter(':checked').addClass('checked');
// Bounds for North America
var strictBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(15.70, -160.50),
new google.maps.LatLng(68.85, -55.90));
// Listen for the dragend event
google.maps.event.addListener(map, 'dragend', function () {
if (strictBounds.contains(map.getCenter())) return;
// We're out of bounds - Move the map back within the bounds
var c = map.getCenter(),
x = c.lng(),
y = c.lat(),
maxX = strictBounds.getNorthEast().lng(),
maxY = strictBounds.getNorthEast().lat(),
minX = strictBounds.getSouthWest().lng(),
minY = strictBounds.getSouthWest().lat();
if (x < minX) x = minX;
if (x > maxX) x = maxX;
if (y < minY) y = minY;
if (y > maxY) y = maxY;
map.setCenter(new google.maps.LatLng(y, x));
});
// Limit the zoom level
google.maps.event.addListener(map, 'zoom_changed', function () {
if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
});
});
});
if (customerlocationID != 0) {
codeAddress(customerlocationID, Rad);
}
}
函数初始化(){
var minZoomLevel=4;
变焦值=7;
geocoder=新的google.maps.geocoder();
geocode=新的google.maps.Geocoder();
//用于设置登录用户的地图中心
$.getJSON('/Dashboard/LoadAddress',函数地理编码(地址){
$。每个(地址、函数(){
customerlocationID=此[“ID”];
var currValAddress=此[“AddressLine1”];
var纬度=此[“纬度”];
var经度=此[“经度”];
LatLang=新的google.maps.LatLng(纬度、经度);
变量地址={
缩放:16,
中心:拉特朗,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=新的google.maps.map(document.getElementById('map'),地址);
var link=$(''+currValAddress+'').data('位置',LatLang);
$('initialPlace').append($('li id=\'List\'class=\'List\'>').append(link));
link.on('click',函数(事件){
var$t=$(event.target);
如果($t.hasClass('checked')){
地图设置中心(拉特朗);
$t.removeAttr(‘已勾选’);
}
$('input[type=“radio”][name=“”+$t.prop('name')+'“]')。而不是($t)。removeClass('checked');
$t.toggleClass('checked');
}).filter(':checked').addClass('checked');
//前往北美的边界
var strictBounds=new google.maps.LatLngBounds(
新google.maps.LatLng(15.70,-160.50),
新google.maps.LatLng(68.85,-55.90));
//收听dragend事件
google.maps.event.addListener(映射'dragend',函数(){
if(strictBounds.contains(map.getCenter())返回;
//我们超出边界-将地图移回边界内
var c=map.getCenter(),
x=c.lng(),
y=c.lat(),
maxX=strictBounds.getNorthEast().lng(),
maxY=strictBounds.getNorthEast().lat(),
minX=strictBounds.getSouthWest().lng(),
minY=strictBounds.getsoutwest().lat();
如果(xmaxX)x=maxX;
如果(ymaxY)y=maxY;
map.setCenter(新的google.maps.LatLng(y,x));
});
//限制缩放级别
google.maps.event.addListener(映射'zoom_changed',函数(){
if(map.getZoom()
在初始化函数中,为单选按钮更改添加事件侦听器,如:
google.maps.event.addDomListener(document.getElementById([your radio button id]), 'click', function() {
google.maps.event.trigger(map, 'resize'); // or whatever
});
文档中有一个例子