谷歌街景有一个静态图像的应用程序接口,引用了in this post。
位于Google Maps街景URL内的静态图像是否需要这些参数?有没有最好的方法来提取它呢?
例如,也许中心500px乘500px的中心的URL的面对和缩放级别?
发布于 2021-11-21 23:27:37
我不能给你一个完整的答案,但这是我能得到的最接近的答案。您需要的相关参数都在URL中,位于"6s“参数之间和刘海(!)之前。最后。因此,我将在URL上进行两次拆分,以获得相关部分。我假设你永远不会在URL的这一部分看到bang,因为Google将它们视为保留字符:
接下来,我将解码URL编码的字符并去掉路径,因为我想使用URLSearchParams从这里操作URL (这两种方法都不起作用):
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams https://www.sitepoint.com/get-url-parameters-with-javascript/
然后我会得到我需要的参数(panoid作为pano,h作为标题,间距和thumbfov作为fov),并将它们放入我的新URL中。请注意,我没有使用cb_client、w或yaw做任何事情,因为我不认为/不知道它们会转换为街景请求中的任何内容:
https://developers.google.com/maps/documentation/streetview/overview#url-parameters
您需要将YOUR_KEY更改为实际的Google Maps Platform API key。还请注意,这些请求没有签名,但如果您正在批量发出请求,您可能会希望这样做:
https://developers.google.com/maps/documentation/streetview/get-api-key
//take the original URL as a
let a = "https://www.google.com/maps/@38.8803747,-77.0404946,3a,75y,71.74h,90.2t/data=!3m7!1e1!3m5!1s5FO2Gol-VCDw3tTsT3iL7A!2e0!6shttps:%2F%2Fstreetviewpixels-pa.googleapis.com%2Fv1%2Fthumbnail%3Fpanoid%3D5FO2Gol-VCDw3tTsT3iL7A%26cb_client%3Dmaps_sv.tactile.gps%26w%3D203%26h%3D100%26yaw%3D355.97687%26pitch%3D0%26thumbfov%3D100!7i13312!8i6656";
//use string.split() twice to isolate the useful bits
let b = a.split("!6s");
let c = (b[1]).split("!");
//c[0] now contains the part we care about
console.log("c[0] is " + c[0]);
//split off the query search parameters and url decode so we can use URLSearchParams
let d = (c[0]).split("%3F");
let e = (d[1]).replace(/%2F/g, "/").replace(/%3F/g, "?").replace(/%3D/g, "=").replace(/%26/g, "&");
console.log("e is " + e);
let params = new URLSearchParams(e);
//define the path for a Street View Static API request
let f = new URLSearchParams();
//grab parameters from the original url and insert them into the new url
if (params.get("panoid")) {
let pano = params.get("panoid");
f.append("pano", pano);
};
if (params.get("h")) {
let heading = params.get("h");
f.append("heading", heading);
};
if (params.get("pitch")) {
let pitch = params.get("pitch");
f.append("pitch", pitch);
};
if (params.get("thumbfov")) {
let fov = params.get("thumbfov");
f.append("fov", fov);
};
//write out the final url
let g = "https://maps.googleapis.com/maps/api/streetview?key=YOUR_KEY&size=500x500&";
console.log("the final URL is " + g + f.toString());
https://stackoverflow.com/questions/70040881
复制相似问题