【问题标题】:Adding a google map to my site将谷歌地图添加到我的网站
【发布时间】:2014-03-04 01:19:18
【问题描述】:

我想在我的网站上添加地图以显示本地商家,但我不想使用图片,我想使用我在某些网站上看到的谷歌地图。

我试过用这个:

https://developers.google.com/maps/documentation/javascript/reference#MapOptions

但它不起作用(你需要把它放在服务器上才能工作吗?我现在只是在本地测试它)

编辑:现在有效,我不知道我做了什么,但它有效。

【问题讨论】:

    标签: javascript html css google-maps


    【解决方案1】:

    您需要添加的东西很少

      <div id="map-canvas" style="height:300px;"></div>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script></script>
            <script>
        jQuery(document).ready(function($){
            codeAddress();
        });
        var geocoder;
        var map;
        function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(ADD LAT, ADD LONG);
      var mapOptions = {
        zoom: 14,
        center: latlng
      }
      map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    }
    
    function codeAddress() {
      geocoder.geocode( { 'address': 'ADD YOUR ADDRESS HERE'}, 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);
        }
      });
    }
    
    google.maps.event.addDomListener(window, 'load', initialize());
    
        </script>
    

    【讨论】:

      【解决方案2】:

      如果您只想创建一个地图来显示您的业务在哪里,就像大多数网站一样,答案要简单得多。

      1 - 转到 Google 地图网站并搜索您要添加的地址。

      2 - 在屏幕右侧的按钮中找到地址后,点击设置

      3 - 选择共享嵌入式地图。

      4 - 选择地图的大小,你会在旁边的栏上看到这样的东西

      <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3192.61190945592!2d174.74475940000002!3d-36.85176959999998!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x6d0d4793eebb1d67%3A0x6830f22a202256c9!2sPonsonby+Rd!5e0!3m2!1sen!2snz!4v1393896861642" width="400" height="300" frameborder="0" style="border:0"></iframe>
      

      放入您的网站并完成工作:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-30
        • 1970-01-01
        • 2012-06-14
        • 2018-09-01
        • 2020-04-21
        • 2015-09-12
        • 1970-01-01
        • 2016-11-22
        相关资源
        最近更新 更多