Jquery 位置可以';使用谷歌地图API时,不能将其设置为中心错误
我有以下JS:Jquery 位置可以';使用谷歌地图API时,不能将其设置为中心错误,jquery,google-maps-api-3,Jquery,Google Maps Api 3,我有以下JS: var map = null; var center_marker = null; var zone = null; $(document).ready(function () { if (GBrowserIsCompatible()) { convert_address_to_long_lat("1600 Pennsylvania Avenue NW Washington, DC 20500", function (point) { map = cre
var map = null;
var center_marker = null;
var zone = null;
$(document).ready(function () {
if (GBrowserIsCompatible()) {
convert_address_to_long_lat("1600 Pennsylvania Avenue NW Washington, DC 20500", function (point) { map = create_map(point); map.setCenter(point, 13); alert('test1'); map.addOverlay(center_marker = new GMarker(point)); draw_the_zones(point); });
//map.setUIToDefault();
}
});
function create_map(point) {
var mapOpt = {
mapTypeId: google.maps.MapTypeId.TERRAIN,
center: point,
zoom: 10
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOpt);
}
function convert_address_to_long_lat(address_string,callback) {
geocoder = new google.maps.Geocoder();
return geocoder.geocode({ 'address': address_string }, callback);
}
function draw_the_zones(point) {
zone = new google.maps.Circle({
radius: 15,
fillColor: '#FF0000',
fillOpacity: 0.2,
map: map
});
zone.bindTo('center', center_marker, 'position');
}
我正在使用jQuery进行事件(顺便说一句)。我不断地犯错误,这个位置不能被设置为某个东西的中心,它没有说
有人知道我做错了什么吗 在这一行:
zone.bindTo('center', center_marker, 'position');
您正在将圆绑定到中心标记点,但在顶部已将其设置为null。尝试使用以下内容将中心标记设置为板条对象:
center_marker = new google.maps.LatLng(53.145,13.438);
但是很明显,将纬度和经度更改为您需要它在地图上的位置。您从
geocoder.geocode()
的回调未设置为正确使用GeocoderResults
对象文字。您将点
视为LatLng
对象。重新构造提供给将\u address\u转换为\u long\u lat()
的回调,使其更像:
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var point = results[0].geometry.location;
map = create_map(point);
map.setCenter(point, 13);
alert('test1');
map.addOverlay(center_marker = new GMarker(point));
draw_the_zones(point);
}
}
请注意,我检查了地理代码的状态以查看我们是否成功,然后从第一个结果的几何体对象检索位置。您应该知道,地理编码器可以从您提供的地址字符串返回多个潜在结果
有关
GeocoderResults
对象的详细信息。我确实将值设置为center\u marker
,您必须滚动到右侧ta位。