我读了很多书,但还是有点糊涂。我正在尝试构建一个应用程序,该应用程序可以在 google 地方获取商业列表并显示“详细信息”,例如地址、评论、图像、位置、描述。
我不想执行搜索,因为我已经知道公司名称和位置(用户不会搜索,而是查看导航到的页面)
我一直在关注这个:https ://developers.google.com/maps/documentation/javascript/places#place_details_requests
并在此处使用代码表单: Google Places API - Places detail request undefined
function initialize() {
var pyrmont = new google.maps.LatLng(50.458447,-3.509552);
map = new google.maps.Map(document.getElementById('map_canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: 5000,
types: ['bar']
};
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++) {
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 + "<br />" + place.formatted_address +"<br />" + place.website + "<br />" + place.rating + "<br />" + place.formatted_phone_number);
infowindow.open(map, this);
});
}
HTML:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
</head>
<body>
<div id="content">
<div id="map_canvas">
map
</div>
</div>
</body>
执行获取请求并将其打印在特定业务列表的 html 中的最简单方法是什么?