是否可以像以下示例一样在 Google 地图上添加地点卡:http ://www.haydensinrye.co.uk/Haydens/Find_Us.html ?
我在Google Maps API 文档n中找不到对此的引用。
我正在使用这种方法嵌入我的地图(在“代码示例”下)。
是否可以像以下示例一样在 Google 地图上添加地点卡:http ://www.haydensinrye.co.uk/Haydens/Find_Us.html ?
我在Google Maps API 文档n中找不到对此的引用。
我正在使用这种方法嵌入我的地图(在“代码示例”下)。
您链接到的站点使用Google Maps Embed。没有办法在 Google Maps API JS v3 中自动获得相同的结果
对于嵌入,如何使用它的示例是:
<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>
如果您想要示例站点之类的内容,您只需设置信息窗口的样式并自动打开它(无需单击标记)。您可以添加路线选择。像那样。如果您想要一个保存选项,请在您的 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>
请注意,已弃用 signed_in 选项,并且在将来的版本中将不起作用。所有这些都可以在 API 文档中找到(我知道它很大)。
我也搜索了很长时间,但我找到了这个例子:
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&z=18&t=m&hl=en-US&gl=AR&mapclient=embed&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&z=18&t=m&hl=en-US&gl=AR&mapclient=embed&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);
});
}