问题
Situation: I'm working on a map feature for a client and I need the ability to get screenshots of a street view, and then display them as a carousel (similar to how Google does it natively). They can choose whatever locations they want in their CMS.
The only way I can think of to do this (taking into account non-tech end users) is to allow them to copy and paste the URL from a street view, and then parse it out.
For example: https://www.google.com/maps/@60.959789,-149.112111,3a,75y,104.14h,94.39t/data=!3m4!1e1!3m2!1sJmW2DmZWQ2bIcAcHlky4-w!2e0
will give you:
After tinkering around, I figure the following breakdown corresponds to paramerters for the Google Street View Image API
60.959789 (lat)
-149.112111 (long)
3a (unknown)
75y (field of view)
104.14h (heading)
94.39t (pitch)
/data=!3m4!1e1!3m2!1sJmW2DmZWQ2bIcAcHlky4-w!2e0 (unknown)
However, when I plug these into the url structure for an image, I get:
https://maps.googleapis.com/maps/api/streetview?size=400x400&location=60.959789,-149.112111&fov=75&heading=104.14&pitch=94.39
Question
What am I screwing up?
Can I do this a better way?
Addendum:
In addition, how can I get the right pano
attribute from relevant photosphere shots? For example, how can I get a Street View Image of this photosphere.
回答1:
I try to avoid answering my own questions, but heres what I found about parsing a URL from Google Street view for use in their Street View Image API.
60.959789 (lat)
-149.112111 (long)
3a (unknown)
75y (field of view)
104.14h (heading)
94.39t (pitch)
/data=!3m4!1e1!3m2!1sJmW2DmZWQ2bIcAcHlky4-w!2e0 (unknown)
The data
attribute is the interesting one. This blog article helped me figure it out.
Each segment of the attribute is preceded by "!", a number from 1 - 5 (or more presumably), and a letter (m, e, etc).
For some reason the fourth element (3rd, when counting from 0) is the pano
attribute.
Therefore, this street view of the Acropolis can be parsed into this url for an image:
https://maps.googleapis.com/maps/api/streetview?size=200x200&location=37.971822,23.726532&fov=75&heading=163.13&pitch=7.599999999999994&pano=fPhZjlaq_sAAAAQYNw-Ypw
I'm not sure what the other attributes pertain to, but I'd like to know.
来源:https://stackoverflow.com/questions/28489214/google-street-view-maps-parsing-url-to-use-as-street-image