我在 google maps api 的帮助下创建了 html 页面。但我不能为给定的地方放置标记。
我的要求是当我在自动完成框中输入位置时,单击搜索按钮后为给定位置放置标记。请任何人帮助我!
我的代码在这里:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
html, body, #map-canvas
{
height: 100%;
margin: 0px;
padding: 0px
}
.controls
{
margin-top: 16px;
border: 1px solid transparent;
border-radius: 2px 0 0 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
height: 32px;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
background-color: #fff;
padding: 0 11px 0 13px;
width: 400px;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
text-overflow: ellipsis;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?YOUR_API_KEY&libraries=places"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(13.0839, 80.2700);
var mapOptions = {
zoom: 7,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
autocomplete();
}
function autocomplete()
{
var source = document.getElementById('start');
var autocomplete = new google.maps.places.Autocomplete(source);
autocomplete.bindTo('bounds', map);
}
function calcRoute() {
var start = document.getElementById('start').value;
var marker = new google.maps.Marker({
position: start,
map: map,
title: 'Hello World!'
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="panel">
<b>Start: </b>
<input id="start" class="controls" type="text"
placeholder="Enter a search location">
<input type="button" value="Route" onclick="calcRoute();">
</div>
<div id = "map-canvas"> </div>
</body>
</html>
提前致谢