![](/img/trans.png)
[英]Issue with Google Maps JavaScript API V3 in <details>-tag
[英]Google Maps API V3 - Javascript Issue
我已经使用 api V3 创建了一个嵌入 Google 地图的站点,它显示了我们的 4 个办公室,然后您可以输入您的邮政编码并检查您与办公室之间的距离,这很有效!
我现在想创建一个径向搜索,我已经找到了如何在网上进行搜索,这很好,并且正处于最后的障碍中,如果可能的话,我需要你的帮助。
我有以下内容:
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);
}
});
}
除了$distance1
之外,我已经设法让一切正常。 应该发生的是,用户从表单中选择距离:比如说 10 英里(谷歌地图以米为单位),当他们点击提交时,会绘制一个半径为 10 英里的圆圈。
正如代码所示,该点已绘制,但未出现圆。
如果我替换distance1 = document.getElementById("distance").value;
distance1 = 16999;
例如,然后出现一个圆圈并且它完美地工作。
对我来说,这一定意味着从表单中拉出distance1
的内容有问题。 为了确定,我做了一个 NaN 测试,它报告内容是一个数字。
我的问题是(以一种非常冗长的方式 - 对此感到抱歉)你知道如何让distance1
从表格中获得价值。
// Add circle overlay and bind to marker var circle = new google.maps.Circle({ map: map, radius: distance1, strokeWeight: 0, fillColor: '#AA0000' });
有问题的部分是radius: distance1
1
可能有助于确保它是一个数字,而不是一个字符串。
distance1 = parseFloat(document.getElementById("distance").value);
(parseInt 可能也可以正常工作,因为它以米为单位,而分数米不会有太大区别)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.