Google maps 将纬度和经度附加到谷歌地图中的标记

Google maps 将纬度和经度附加到谷歌地图中的标记,google-maps,geolocation,Google Maps,Geolocation,我正试图在谷歌地图中将lat和long附加到我的标记上,这样我就可以为每个标记添加标题 我似乎不知道我错过了什么 function getPlaces(index, placesArray) { placesSearch.textSearch({query: placesArray[index]}, function (placesResult) { if(index === 0){ markerAr

我正试图在谷歌地图中将lat和long附加到我的标记上,这样我就可以为每个标记添加标题

我似乎不知道我错过了什么

function getPlaces(index, placesArray)
    {
        placesSearch.textSearch({query: placesArray[index]}, function (placesResult)
        {
            if(index === 0){
                markerArray.forEach(marker =>
                {
                    marker.setMap(null);
                });
                map.setCenter(placesResult[0].geometry.location);
            }
            if(placesResult && placesResult[0])
            {
                markerArray.push(new google.maps.Marker({
                    position: placesResult[0].geometry.location.LatLng,
                    map: map,
                    clickable: true,
                    title: "Click for more details"

                }));
            }

            if(index < placesArray.length - 2)
            {
                getPlaces(++index, placesArray);
            }
        });
    }
函数getPlaces(索引,placesArray) { textSearch({query:placesArray[index]},函数(placesResult) { 如果(索引==0){ markerArray.forEach(marker=> { marker.setMap(空); }); map.setCenter(placesResult[0].geometry.location); } if(placesResult&&placesResult[0]) { markerArray.push(新的google.maps.Marker)({ 位置:placesResult[0]。geometry.location.LatLng, 地图:地图, 可点击:正确, 标题:“单击查看更多详细信息” })); } 如果(索引您缺少一个信息窗口

应该是这样的

...
if(placesResult && placesResult[0])
{
    var marker = new google.maps.Marker({
        position: placesResult[0].geometry.location.LatLng,
        map: map,
        clickable: true,
        title: "Click for more details"

    });
    markerArray.push(marker);
    // attach an onClick event
    marker.addListener('click', function() {
      // first we need to know which marker was clicked on
      var index = markerArray.indexOf(this);
      var position = markerArray[index].getPosition();
      var contentString = 'marker position: ' + position.lat() + ',' + position.lng();
      var infowindow = new google.maps.InfoWindow({
        content: contentString,
        position: position,
        map: map
      });

    })

}
...