gpt4 book ai didi

google-maps - 谷歌地图上的巴士站列表

转载 作者:行者123 更新时间:2023-12-04 15:03:27 25 4
gpt4 key购买 nike

我正在尝试构建网络应用程序,您可以在其中输入您的地址,它会为您提供您所在地区的巴士站列表。我想为此使用谷歌地图,但我找不到为此使用它们的方法。有没有办法以 JSON 或 XML 格式获取 map 上的点列表?我尝试了 Google Maps Places API,但它并没有以这种方式工作。我唯一发现的是这个例子 - http://gmaps-samples-v3.googlecode.com/svn/trunk/localsearch/places.html但这不是我需要的。

那么,有人知道吗?

最佳答案

我认为它可以帮助你

<script>
// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">

var map;
var infowindow;

function initMap() {
var pyrmont = {lat: 38.06908229560463, lng: 46.31730562744135};

map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 15
});

infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: pyrmont,
radius: 1000,
types: ['bus_station','transit_station']

}, callback);
}

function callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}

function createMarker(place) {
var placeLoc = place.geometry.location;
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);
});
}
</script>

关于google-maps - 谷歌地图上的巴士站列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7139118/

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