gpt4 book ai didi

javascript - 删除谷歌地点类型之间的逗号

转载 作者:行者123 更新时间:2023-11-30 05:47:24 25 4
gpt4 key购买 nike

我正在尝试使用 Google Places API。我从 https://developers.google.com/maps/documentation/javascript/examples/place-search-pagination 得到这些代码.

var map, placesList;

function initialize() {
var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);

map = new google.maps.Map(document.getElementById('map-canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 17
});

var request = {
location: pyrmont,
radius: 500,
types: ['store']
};

placesList = document.getElementById('places');

var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}

function callback(results, status, pagination) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
return;
} else {
createMarkers(results);

if (pagination.hasNextPage) {
var moreButton = document.getElementById('more');

moreButton.disabled = false;

google.maps.event.addDomListenerOnce(moreButton, 'click',
function() {
moreButton.disabled = true;
pagination.nextPage();
});
}
}
}

function createMarkers(places) {
var bounds = new google.maps.LatLngBounds();

for (var i = 0, place; place = places[i]; i++) {
var image = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};

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

placesList.innerHTML += '<li>' + place.name + '</li>';

bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
}

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

使用这些代码,我从位置获取名称,并将其更改为类型。现在我得到了一个类型列表,但它们之间有逗号。

    placesList.innerHTML += '<li>' + place.types + '</li>';

如何删除逗号?例如它们看起来像这样:

<li>accounting,airport,amusement_park</li>
<li>aquarium,art_gallery,atm,bakery</li>
<li>bank,bar,beauty_salon</li>

我希望将逗号替换为空格。有人可以帮助我吗?

最佳答案

使用加入

place.types.join(" ")

关于javascript - 删除谷歌地点类型之间的逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17255683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com