【发布时间】:2015-07-30 05:44:10
【问题描述】:
我正在尝试通过 google maps api 街景显示企业内部。我首先检索places_id 并使用它来检索可能可用的任何街景全景图。这在本周早些时候起作用并且已经停止。不过,我不知道为什么。显示交互式地图的 div 显示为灰色,并带有一些 google 工件,并且控制台记录了一个错误,即 google 生成的 url 返回了 404。有人遇到过这种情况吗?
下面的代码也在我的JS Fiddle
var map;
var panorama;
$('#thebutton').click(function () {
map = new google.maps.Map(document.getElementById('map-canvas'));
var infowindow = new google.maps.InfoWindow();
var place_id = 'ChIJ-_RcvsBV2YARhkUbjSD3Vi4';
var placeservice = new google.maps.places.PlacesService(map);
var placesRequest = {
placeId: place_id
};
placeservice.getDetails(placesRequest, function (results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results.geometry.location
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(results.name);
infowindow.open(map, this);
});
var brewerystreetview = new google.maps.LatLng(results.geometry.location.A, results.geometry.location.F);
var sv = new google.maps.StreetViewService();
panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), {
center: new google.maps.LatLng(results.geometry.location.lat(), results.geometry.location.lng()),
zoom: 0
});
sv.getPanorama({
location: brewerystreetview,
radius: 0
}, processSVData);
}
});
});
function processSVData(data, status) {
if (status == google.maps.StreetViewStatus.OK) {
var marker = new google.maps.Marker({
position: data.location.latLng,
map: map,
title: data.location.description
});
panorama.setPano(data.location.pano);
panorama.setPov({
heading: 0,
pitch: 0
});
panorama.setVisible(true);
google.maps.event.addListener(marker, 'click', function () {
var markerPanoID = data.location.pano;
// Set the Pano to use the passed panoID.
panorama.setPano(markerPanoID);
panorama.setPov({
heading: 0,
pitch: 0
});
panorama.setVisible(true);
panorama.show();
});
}
}
【问题讨论】:
-
只是一个旁注,因为它似乎不是主要问题:
var brewerystreetview = new google.maps.LatLng(results.geometry.location.A, results.geometry.location.F);A & F 是无证属性。你应该使用lat()和lng()函数,所以new google.maps.LatLng(results.geometry.location.lat(), results.geometry.location.lng());(你在下面几行......) -
嘿@MrUpsidown,感谢您的建议。我做了那个小改动,全景开始按预期填充! 除了在我的 android 上。呃不知道为什么这在一两天前对未记录的属性有效。但是,我会接受的!谢谢!
-
嗯,这些属性可能会发生变化,特别是如果您不强制使用 API 版本。但是这里有一些奇怪的东西,因为我在一小时前在你的小提琴中改变了它,但它没有用。现在它可以工作了。错误是
getPanorama不是函数(?!)。我什至尝试过使用较旧的 API 版本,但问题是相同的。所以我认为 Google 有问题? -
这是可能的,但我通常会先怀疑我的代码,然后再指向其他任何内容。 :) 这个问题发生在我一天的大部分时间里(而昨天它起作用了)。
标签: javascript jquery css google-maps google-maps-api-3