【发布时间】:2016-05-18 09:38:12
【问题描述】:
所以我找到了几种将地图放到我的页面上的方法,第一个版本是使用这样的 iframe:
<iframe src="https://www.google.com/maps/embed/v1/place?key=[APIKEY]&q=place_id:[PlaceID]"></iframe>
它给出了一个标记,如下图所示,标记旁边的地名:
但是,这并不完美,因为它在左上角有那个巨大的白框,并且根据许多 SO 帖子,您无法将其删除。
所以我想我会尝试 js 路线所以有以下代码:
var map = new google.maps.Map(this, {
zoom: 15,
center: { lat: options.latitude, lng: options.longitude }
});
marker = new google.maps.Marker({
map: map,
title: options.title
});
marker.setPlace({
placeId: options.placeId,
location: { lat: options.latitude, lng: options.longitude }
});
var infowindow = new google.maps.InfoWindow(
{
content: '<strong>' + options.title + '</strong><br />' + options.address
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
所有options 都用正确的值填充。但是,这会生成以下更好的地图,因为它没有白框:
但是,即使第二张地图使用与第一张相同的地点 ID,第二张地图上也没有商店文字。
有什么方法可以更改 js 代码,使其包含像 iframe 版本中的位置文本?我已经搜索了所有文档和示例,但找不到任何设置来执行此操作
【问题讨论】:
标签: google-maps google-maps-api-3 google-places-api