I created html page with the help of google maps api. But I can't place the marker for given place.

我在google maps api的帮助下创建了html页面。但我无法将标记放在给定的位置。

My requirement is when I enter place in autocomplete box, Place the marker for given place after click search button. Please anyone help me!

我的要求是当我在自动完成框中输入位置时,单击搜索按钮后放置给定位置的标记。请有人帮帮我!

My code here:

我的代码在这里:

<!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>

更多相关文章

  1. 使用CSS类作为JS标记是一种不好的做法吗?
  2. 在Django模板标记库中导入外部库时出错
  3. 通过分隔符计数和位置从数据框中提取特定文本
  4. python 按位置关系输出矩阵元素
  5. scikit-learn:在标记化时不要分隔带连字符的单词
  6. 支持c和python之间的跨语言(c)标记的代码编辑器
  7. MYSQL从同一个表中选择标记关联的id
  8. sqlserver2008r2查找非中文字母数字出现的第一个位置
  9. 如何将图像加载到PictureBox;基于存储在DataBase中的图像位置

随机推荐

  1. 不就看一下Java后端开发书架吗?这有啥不行
  2. 9 个强大的 JavaScript 小技巧[每日前端
  3. 从 JavaScript、ES6、ES7 到 ES10,你学到
  4. 用 globalThis 访问全局对象[每日前端夜
  5. 生产环境下的 Node.js 日志记录方案[每日
  6. 观察者模式
  7. 史上最全最强SpringMVC详细示例实战教程(
  8. Java中使用Jedis操作Redis
  9. 熬10天夜,肝出了这个PDF版「软件安装手册
  10. 阅完此文,Vue响应式不再话下