简体   繁体   English

Google 地图添加地标

[英]Google Maps add a placecard

Is it possible to add a place card on Google maps like in this example: http://www.haydensinrye.co.uk/Haydens/Find_Us.html ?是否可以在 Google 地图上添加地点卡片,例如在此示例中: http : //www.haydensinrye.co.uk/Haydens/Find_Us.html

I couldn't find a reference to this in the Google Maps API documentation n.我在Google Maps API 文档中找不到对此的引用。

I'm using this method to embed my map (under "Code Examples").我正在使用这种方法嵌入我的地图(在“代码示例”下)。

The site you linked to uses Google Maps Embed .您链接到的网站使用Google Maps Embed There is no way to get the same in the Google Maps API JS v3 automatically在 Google Maps API JS v3 中没有办法自动获得相同的

For embed, an example on how to use it is:对于嵌入,有关如何使用它的示例是:

   <iframe
      width="600"
      height="450"
      frameborder="0" style="border:0"
      src="https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY
        &q=Space+Needle,Seattle+WA" allowfullscreen>
    </iframe>

If you want something like the sample site you should just style your info window and open it automatically (without having to click the marker).如果您想要类似示例站点的内容,您应该只设置信息窗口的样式并自动打开它(无需单击标记)。 You can add directions opt.您可以添加路线选择。 like that.像那样。 If you want a save option add signed_in=true after your API key.如果您想要保存选项,请在 API 密钥后添加signed_in=true

<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&signed_in=true&callback=initMap">
</script>

Note that the signed_in option is deprecated and will not work in future versions.请注意, signed_in 选项已弃用,在未来版本中将无法使用 All of it can be found in the API documentation (it's huge I know).所有这些都可以在 API 文档中找到(我知道它很大)。

I searched for a long time too but I found this example:我也搜索了很长时间,但我找到了这个例子:

https://codepen.io/jonathanphz/pen/Wxorqj https://codepen.io/jonathanphz/pen/Wxorqj

//HTML
<div class="map-container">
    <div class="placeDiv">
        <div class="placecard__container">

          <div class="placecard__left">
            <p class="placecard__business-name">China Bistro Name Goes Here</p>
            <p class="placecard__info">9 Avenida Ramón Luis Rivera, Bayamón, 00961, Puerto Rico</p>
            <a class="placecard__view-large" target="_blank" href="https://maps.google.com/maps?ll=18.416035,-66.162618&amp;z=18&amp;t=m&amp;hl=en-US&amp;gl=AR&amp;mapclient=embed&amp;cid=2947398168469204860" id="A_41">View larger map</a>
          </div> <!-- placecard__left -->

          <div class="placecard__right">
              <a class="placecard__direction-link" target="_blank" href="https://maps.google.com/maps?ll=18.416035,-66.162618&amp;z=18&amp;t=m&amp;hl=en-US&amp;gl=AR&amp;mapclient=embed&amp;daddr=Roberto%20Perez%20Obregon%20Law%20Office%209%20Avenida%20Ram%C3%B3n%20Luis%20Rivera%20Bayam%C3%B3n%2C%2000961%20Puerto%20Rico@18.4160349,-66.1626177"
              id="A_9">
                  <div class="placecard__direction-icon"></div>
                  Directions
              </a>
          </div> <!-- placecard__right -->

        </div> <!-- placecard__container -->
    </div> <!-- placeDiv -->
</div> <!-- map-container -->
<div id="map-canvas"></div>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" type="text/javascript"></script>


//css
#map-canvas{
  height: 500px;
  width: 100%;
  max-width: 100%;
  position: relative;
}

.placeDiv {
  z-index: 9999;
  position: absolute;
}

.map-container {
  position: relative;
}

.placecard {

  &__container {
    box-shadow: rgba(0, 0, 0, 0.298039) 0px 1px 4px -1px;
    max-width: 330px;
    width: 100%;
    background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box;
    border-radius: 2px 2px 2px 2px;
    font: normal normal normal normal 11px / normal Roboto, Arial, sans-serif;
    margin: 10px;
    padding: 9px 4px 9px 11px;
    overflow: hidden;
  }

  &__left {
    float: left;
    width: 75%;
  }

  &__right {
    text-align: center;
    float: left;
    width: 25%;
  }

  &__business-name {
    cursor: default;
    height: 19px;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 200px;
    perspective-origin: 100px 9.5px;
    transform-origin: 100px 9.5px;
    font: normal normal 500 normal 14px / normal Roboto, Arial;
    overflow: hidden;
    margin: 0;
  }

  &__info {
    color: rgb(91, 91, 91);
    cursor: default;
    height: 32px;
    width: 200px;
    column-rule-color: rgb(91, 91, 91);
    perspective-origin: 100px 16px;
    transform-origin: 100px 16px;
    border: 0px none rgb(91, 91, 91);
    font: normal normal normal normal 12px / normal Roboto, Arial;
    margin: 6px 0px 0px;
    outline: rgb(91, 91, 91) none 0px;
  }

  &__direction-icon {
    background: rgba(0, 0, 0, 0) url("https://maps.gstatic.com/mapfiles/embed/images/entity11.png") repeat scroll 0px 0px / 70px 210px padding-box border-box;
    height: 22px;
    width: 22px;
    margin-right: auto;
    margin-left: auto;
  }

  &__direction-link {
    color: rgb(58, 132, 223);
    display: block;
    height: 43px;
    text-decoration: none;
    width: 54.7344px;
  }

  &__view-large {
    display: block;
    margin-top: 10px;
    color: rgb(58, 132, 223);
    text-decoration: none;
  }

}


//js
// if HTML DOM Element that contains the map is found...
if (document.getElementById('map-canvas')) {

  // Coordinates to center the map
  var myLatlng = new google.maps.LatLng(18.41604, -66.1626177);

  // Other options for the map, pretty much selfexplanatory
  var mapOptions = {
    zoom: 16,
    center: myLatlng,
    scrollwheel: false,
    query: 'Roberto Perez Obregon Law Office',
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  // Attach a map to the DOM Element, with the defined settings
  var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

  var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: "Roberto Perez Obregon Law Office",
  });


  //Resize map
  google.map.event.addDomListener(window, 'load', initialize);
  google.map.event.addDomListener(window, "resize", function() {
    var center = map.getCenter();
    google.map.event.trigger(map, "resize");
    map.setCenter(center);
  });

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM