删除Google地点类型之间的逗号 [英] Remove commas between google places types
本文介绍了删除Google地点类型之间的逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Google Places API。
我从 https://开发者处获得了这些代码。 google.com/maps/documentation/javascript/examples/place-search-pagination 。
I'm trying to use Google Places API. I got these codes from 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);
通过这些代码,我可以从位置获取名称,并将其更改为类型。现在我得到一个包含类型的列表,但它们之间有逗号。
With these codes I get the names from locations, I changed it to types. And now I get a list with types, but they have comma's between them.
placesList.innerHTML += '<li>' + place.types + '</li>';
如何删除逗号?
例如它们看起来像这样:
How can I remove the comma's? for example they look like this:
<li>accounting,airport,amusement_park</li>
<li>aquarium,art_gallery,atm,bakery</li>
<li>bank,bar,beauty_salon</li>
我希望逗号被空格替换。有人可以帮我吗?
I want the comma's to be replaced with a space. Can someone help me?
推荐答案
使用加入
place.types.join(" ")
这篇关于删除Google地点类型之间的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文