onclick 后删除地理编码标记
我正在使用谷歌地图 - 方向和地理编码。加载页面时,地理编码会放置一个标记。当用户单击提交按钮时是否可以删除此标记?我之前问过,有人建议使用:
marker.setMap(null);
但我不太确定在哪里放置那段代码
这是代码:
var address = document.getElementById("address").textContent.replace(/\n/g, " ");
geocoder.geocode( { 'address': address},
function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
var from = document.getElementById("from").value;
var to = document.getElementById("to").value;
var request = {
origin: from,
destination: to,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
document.getElementById("map").style.width = "70%";
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
提前致谢
I am using google maps- directions and geocoding. The geocode places a marker when the page loads. Is it possible to have this marker removed when a user clicks the submit button? I asked earlier and somebody suggested using:
marker.setMap(null);
but I'm not too sure where to place that bit of code
Here is the code:
var address = document.getElementById("address").textContent.replace(/\n/g, " ");
geocoder.geocode( { 'address': address},
function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
var from = document.getElementById("from").value;
var to = document.getElementById("to").value;
var request = {
origin: from,
destination: to,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
document.getElementById("map").style.width = "70%";
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
提交按钮在哪里?
当然,这是假设
marker.setMap(null);
有效。Where is the submit button?
This is assuming
marker.setMap(null);
works, of course.