Javascript 谷歌地图,使用place_id创建地图

Javascript 谷歌地图,使用place_id创建地图,javascript,google-maps,google-maps-api-3,google-places-api,Javascript,Google Maps,Google Maps Api 3,Google Places Api,是否可以使用Google API为网站创建一个与此完全相同的地图: 所以我想要的是把这个地方Id传递给API,得到一个像Googleplex这样的地方,我想要标记在上面,地名是红色的 我使用的是api v3,我想直接将不使用搜索的地方的id传递给它,如下所述: 我也不想嵌入预生成的地图,因为需要覆盖的区域地图对页面宽度和高度是动态的。使用和getDetails()方法 function initialize() { var map = new google.maps.Map(doc

是否可以使用Google API为网站创建一个与此完全相同的地图:

所以我想要的是把这个地方Id传递给API,得到一个像Googleplex这样的地方,我想要标记在上面,地名是红色的

我使用的是api v3,我想直接将不使用搜索的地方的id传递给它,如下所述:

我也不想嵌入预生成的地图,因为需要覆盖的区域地图对页面宽度和高度是动态的。

使用和
getDetails()
方法

function initialize() {

    var map = new google.maps.Map(document.getElementById('map-canvas'), {
        center: new google.maps.LatLng(-33.8665433, 151.1956316),
        zoom: 15
    });

    var request = {
        placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
    };

    var infowindow = new google.maps.InfoWindow();
    var service = new google.maps.places.PlacesService(map);

    service.getDetails(request, function (place, status) {

        if (status == google.maps.places.PlacesServiceStatus.OK) {

            var marker = new google.maps.Marker({
                map: map,
                position: place.geometry.location
            });

            google.maps.event.addListener(marker, 'click', function () {
                infowindow.setContent(place.name);
                infowindow.open(map, this);
            });
        }
    });
}

google.maps.event.addDomListener(window, 'load', initialize);

请参见

该函数有3个输入,您应该将它们存储在代码中。 (在这里您可以找到地点\u id:) 您应该更改地图ID(或将其作为输入传递)


这很接近,但我仍然希望获得我链接的地图上的内容,因此当鼠标悬停时,地名是红色和蓝色的。使用API无法实现这一点。看看图书馆。
function initMap(place_id, lat, lng){
    var map = new google.maps.Map(document.getElementById('js-concrete_map'), {
        center: {lat: lat, lng: lng},
        zoom: 15
    });
    var infowindow = new google.maps.InfoWindow();
    var service = new google.maps.places.PlacesService(map);

    service.getDetails({
        placeId: place_id
    }, function(place, status) {
        if (status === google.maps.places.PlacesServiceStatus.OK) {
            var marker = new google.maps.Marker({
                map: map,
                position: place.geometry.location
          });
          google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(place.name);
            infowindow.open(map, this);
          });
        }
    });
}