我正在使用Google Places API
检索有关地点的数据,但无法找到如何获取该地点的图片,Google Places API
只是提供了不是相同。例如,当您在Web浏览器中搜索Google地图中的某个地点时,我需要您获得的照片。通常,Panoramio中有更多图片,但Panoramio API只能按位置搜索图片,而不能查找特定餐厅或酒店名称。有任何想法吗?如何从Google地图或地点获取地点的图片API
回答
Places API会为您提供place detail response中的坐标(经度和纬度)然后您可以将坐标发送到Panoramio API。
例如(来自实施例中API文档绘制):
https://maps.googleapis.com/maps/api/place/details/json?reference=<big long key for place>&sensor=true&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI
响应:
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "48",
"short_name" : "48",
"types" : [ "street_number" ]
},
{
"long_name" : "Pirrama Road",
"short_name" : "Pirrama Road",
"types" : [ "route" ]
},
{
"long_name" : "Pyrmont",
"short_name" : "Pyrmont",
"types" : [ "locality", "political" ]
},
{
"long_name" : "NSW",
"short_name" : "NSW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "AU",
"short_name" : "AU",
"types" : [ "country", "political" ]
},
{
"long_name" : "2009",
"short_name" : "2009",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "5/48 Pirrama Road, Pyrmont NSW, Australia",
"formatted_phone_number" : "(02) 9374 4000",
"geometry" : {
"location" : {
"lat" : -33.8669710,
"lng" : 151.1958750
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "4f89212bf76dde31f092cfc14d7506555d85b5c7",
"international_phone_number" : "+61 2 9374 4000",
"name" : "Google Sydney",
"rating" : 4.60,
"reference" : "CnRlAAAAAfV6JIqSzL8Cf4VnXn0EaI1d5k3IPhdkEonq0MxiUbQFFSVuptVbXbNH4mrevb0bc7G8yWqTUv76i4KTuO_Wf3OrRHjCJJwzQ0mNLjbYGSVqy2eqyrgOUkl6S_sJfTbHzWZYrfPy7KZaet0mM5S6thIQJYuy5v_JD--ZxXEJLWTQRRoU5UaciXBBo89K-bce18Ii9RsEIws",
"types" : [ "store", "establishment" ],
"url" : "http://maps.google.com/maps/place?cid=10281119596374313554",
"vicinity" : "5/48 Pirrama Road, Pyrmont",
"website" : "http://www.google.com.au/"
},
"status" : "OK"
}
我们可以看到,坐标是 “位置”:{ “lat”:-33.8669710, “lng”:151.1958750 }
然后我们可以向Panoramio发送一个请求,插入坐标,在两边加上一个小摆动室(我做了+/- 0.002度,在赤道200米x200平方米的形状,一般较小)。 http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=20&minx=-33.868&miny=151.193&maxx=-33.864&maxy=151.197&size=medium&mapfilter=true
你可能需要做响应的一些过滤,以获得最接近的照片,但是这应该给你一些帮助。
Places API可只直接添加到API中要求照片的能力:https://developers.google.com/maps/documentation/javascript/places#places_photos
你有没有任何示例代码 – r4jiv007
Places API可现在支持一个地方的照片是否可用于Place Search request回报和多达十张相片,Place Details request。
如果照片阵列与您的要求退换,您可以传递一个包含照片对象photo_reference
与maxheight
和/或maxwidth
,sensor
和key
参数Place Photo request:
https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CnRvAAAAwMpdHeWlXl-lH0vp7lez4znKPIWSWvgvZFISdKx45AwJVP1Qp37YOrH7sqHMJ8C-vBDC546decipPHchJhHZL94RcTUfPa1jWzo-rSHaTlbNtjh-N68RkcToUCuY9v2HNpo5mziqkir37WU8FJEqVBIQ4k938TI3e7bf8xq-uwDZcxoUbO_ZJzPxremiQurAYzCTwRhE_V0&sensor=false&key=AddYourOwnKeyHere
请参阅documentation了解更多详情。
我看到这张照片。但我想在JS中使用它。我可以使用带有URL的JSON格式吗? – user132522
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Places Searchbox</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 50%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#description {
font-family: Roboto;
font-size: 15px;
font-weight: 300;
}
#infowindow-content .title {
font-weight: bold;
}
#infowindow-content {
display: none;
}
#map #infowindow-content {
display: inline;
}
.pac-card {
margin: 10px 10px 0 0;
border-radius: 2px 0 0 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
background-color: #fff;
font-family: Roboto;
}
#pac-container {
padding-bottom: 12px;
margin-right: 12px;
}
.pac-controls {
display: inline-block;
padding: 5px 11px;
}
.pac-controls label {
font-family: Roboto;
font-size: 13px;
font-weight: 300;
}
#pac-input {
background-color: #fff;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
margin-left: 12px;
padding: 0 11px 0 13px;
text-overflow: ellipsis;
width: 400px;
}
#pac-input:focus {
border-color: #4d90fe;
}
#title {
color: #fff;
background-color: #4d90fe;
font-size: 25px;
font-weight: 500;
padding: 6px 12px;
}
#target {
width: 345px;
}
</style>
</head>
<body>
<input id="pac-input" class="controls" type="text" placeholder="Search Box">
<div id="map"></div>
<div id="place-list"></div>
<script>
// This example adds a search box to a map, using the Google Place Autocomplete
// feature. People can enter geographical searches. The search box will return a
// pick list containing a mix of places and predicted search terms.
// 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">
function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.8688, lng: 151.2195},
zoom: 13,
mapTypeId: 'roadmap'
});
// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});
var markers = [];
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
// Clear out the old markers.
markers.forEach(function(marker) {
marker.setMap(null);
});
markers = [];
// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
var icon = {
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 photoUrl = place.photos[0].getUrl({maxWidth: 400, maxHeight: 400});
var img = document.createElement("img");
img.setAttribute('src', photoUrl + "photo.jpg");
document.getElementById('place-list').appendChild(img);
// Create a marker for each place.
markers.push(new google.maps.Marker({
map: map,
icon: photos[0].getUrl({'maxWidth' : 35,maxHeight' : 35})
title: place.name,
position: place.geometry.location
}));
if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=<KEY_API>&libraries=places&callback=initAutocomplete"
async defer></script>
</body>
</html>
虽然这段代码可能会解决这个问题,但[包括解释](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)确实有助于提高帖子的质量。请记住,您将来会为读者回答问题,而这些人可能不知道您的代码建议的原因。也请尽量不要用解释性注释来挤占代码,这会降低代码和解释的可读性! – kayess
- 1. 如何从Google地图检索我的地点地图数据?
- 2. 用于获取随机地点(YQL!,Google地图,...)的API
- 3. 如何从Google静态地图API获取图片
- 4. 未从地点ID获取Google地点信息照片。无效的Api密钥?
- 5. 从google地图获取图片iframe
- 6. Google地图/ Places API - 在用户点击时获取地址place_id?
- 7. 如何使用Google地图获取附近的地点?
- 8. 如何从Google地图地理编码API获取JSON请求
- 9. 无法从Google地图使用位置获取地点
- 10. 从Google地图中“分享此地点”获取坐标
- 11. 如何使用Google API获取某个地点的地址
- 12. 如何从C#中的Google地图获取海拔点?
- 13. 如何从HERE地图获取特定地点的GPS坐标
- 14. 如何获取/放Kotlin内部地图或地图的地图
- 15. 获取Factual API的地点照片
- 16. 谷歌地图 - 获取点在地图上的点
- 17. 如何从Google/Bing地图获取顶点数据?
- 18. 来自“我的地点”地图的静态Google地图图像?
- 19. 点击地图后获取地址
- 20. 结合地图点 - 谷歌地图API
- 21. 如何在地图上点击链接地址获取地址?
- 22. iOS - Google地图上的附近地点
- 23. Google地图上的30,000个地点
- 24. Google地图上的可点击地名
- 25. Google地球或Google地图?
- 26. Google地图API在地图上重复列出信用点
- 27. 新加坡Google地图API v3的标准地点/子地点列表?
- 28. Google地球插件API - 如何获取当前地图比例?
- 29. 通过引用获取地点详细信息 - Google地图 - Json
- 30. jQuery Google地图根据点击获取地址
谢谢我在想这件事,它不一定给图片的正确位置,但我想它是最接近你可以得到的。它只是奇怪,他们有网站上的照片,但不会给他们无论如何在地图或地方api – user975869
Panoramio不再是一件事。该网站(http://www.panoramio.com/)说“Panoramio在2016年11月4日之后不再可用”。 API请求全部以404 Not Found回应。 – salomvary