gpt4 book ai didi

javascript - Google map V3.0 地点 Api

转载 作者:行者123 更新时间:2023-12-02 20:17:30 24 4
gpt4 key购买 nike

我正在开发一个 GoogleMap 项目。我对 3 天的任务感到震惊(真的是漫长的日子).. 无法完成任务。我是 JavaScript 初学者。

I want to achieve something as shown in the Link for a UK Location. I have changed it to the Uk Location(LONDON) and changed the types to bank. Basically I was expecting the banks pin in the given radius to display. But it is not doing that. I changes the types to train_station, strangley i am getting wrongoutput.

我正在使用的代码如下所示。谁能帮帮我吗..

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Place Search</title>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places"></script>

<style type="text/css">
#map {
height:500px;
width:100%;

}
</style>

<script type="text/javascript">

var map;
var service;
var infowindow;

function initialize() {

// Australia PostCode
//var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);
// Uk Post Code
//Northampton
//var pyrmont = new google.maps.LatLng(52.238, -0.895);
//London
var pyrmont = new google.maps.LatLng(51.4916807, -0.1920284);

// var pyrmont = new google.maps.LatLng(40.704, -70.0083);


map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 12
});
var request = {
location: pyrmont,
radius: '50000',
types: ['train_station']

};
infowindow = new google.maps.InfoWindow();
service = new google.maps.places.PlacesService(map);
service.search(request, callback);
}

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

function createMarker(place) {

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

position: new google.maps.LatLng(placeLoc.lat(), placeLoc.lng())
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}

</script>
</head>
<body onload="initialize()">
<div id="map"></div>
<div id="text">
<pre>
var request = {
bounds: new google.maps.LatLngBounds(
new google.maps.LatLng(-33.867114, 151.1957),
new google.maps.LatLng(-33.866755, 151.196138)),
types: ['political']
};
</pre>
</div>
</body>
</html>

最佳答案

Google 地方信息目前在伦敦似乎没有太多内容。当您完全省略类型数组时,它只返回少数位置。它们似乎都不是火车站或银行。因此,您必须首先将火车站和银行添加到 Google 地方信息。

尽管 Google 地方信息中目前缺乏伦敦的数据,但 API 正在运行。例如,如果您使用“museum”作为类型数组中的元素,您可以看到一堆结果。

不过,不知道“train_station”错误输出问题是怎么回事。 Google Places API 是实验性的。也许您应该向 Google 提交错误。问题跟踪器位于 http://code.google.com/p/gmaps-api-issues/issues/list 。提交错误时,从第一个下拉项中选择“Places API - Bug”。

关于javascript - Google map V3.0 地点 Api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6057938/

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