谷歌地图API V3-Javascript问题
我已经创建了一个网站嵌入谷歌地图使用api V3显示我们的4个办公室,然后你可以键入你的邮政编码,并检查你和一个办公室之间的距离,这工作 我现在想创建一个径向搜索,我已经找到了如何在线完成它,这是伟大的,我在最后的障碍,这是我需要你的帮助,如果可能的话 我有以下资料:谷歌地图API V3-Javascript问题,javascript,google-maps-api-3,Javascript,Google Maps Api 3,我已经创建了一个网站嵌入谷歌地图使用api V3显示我们的4个办公室,然后你可以键入你的邮政编码,并检查你和一个办公室之间的距离,这工作 我现在想创建一个径向搜索,我已经找到了如何在线完成它,这是伟大的,我在最后的障碍,这是我需要你的帮助,如果可能的话 我有以下资料: geocoder = new google.maps.Geocoder(); // creating a new geocode object // getting the two address val
geocoder = new google.maps.Geocoder(); // creating a new geocode object
// getting the two address values
address1 = document.getElementById("addresses1").value;
distance1 = document.getElementById("distance").value;
// finding out the coordinates
if (geocoder)
{
geocoder.geocode( { 'address': address1}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
//location of first address (latitude + longitude)
location1 = results[0].geometry.location;
// Location Marker
var marker = new google.maps.Marker({
map: map,
position: location1,
title: 'Random text'
});
// Add circle overlay and bind to marker
var circle = new google.maps.Circle({
map: map,
radius: distance1,
strokeWeight: 0,
fillColor: '#AA0000'
});
circle.bindTo('center', marker, 'position');
} else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}
除了$distance 1
之外,我已设法使所有功能正常工作。应该发生的是,用户从表单中选择距离:比如说10英里(谷歌地图设置为米),当他们点击提交时,会画一个半径为10英里的圆
代码显示时,绘制点,但不显示圆
如果我替换distance 1=document.getElementById(“distance”).value代码>具有距离1=16999代码>例如,然后出现一个圆,它可以完美地工作
对我来说,这一定意味着当从表单中提取distance 1
时,它的内容有问题。我已经做了一个NaN测试,只是为了确定,它报告的内容是一个数字
我的问题是(以一种非常冗长的方式-对此表示抱歉)您是否知道如何从表单中获取distance 1
值
//添加圆覆盖并绑定到标记
var circle=new google.maps.circle({
地图:地图,
半径:距离1,
冲程重量:0,
填充颜色:“#AA0000”
});代码>
所讨论的部分是半径:距离1
可能有助于确保它是一个数字,而不是字符串
distance1 = parseFloat(document.getElementById("distance").value);
(parseInt可能也可以,因为它是以米为单位的,分数米不会有太大区别)我想这是因为radius需要一个数字,而distance1是一个字符串。您是否尝试过distance1=parseInt(document.getElementById(“distance”).value);