Exact coordinates of image using Google Street View Static API

107 Views Asked by At

I'm using Google Street View Static API to get a streetview image of a certain object located at a certain location. My process follows those steps:

  1. First I query metadatas using my object coordinates (lat,lon). For that i'm using: "https://maps.googleapis.com/maps/api/streetview/metadata?parameters"
  2. Then I get coordinates of a supposed streetview panorama (lat_pano, lon_pano )
  3. Using those coordinates I query an image with heading, fov, pitch size parameters and the panorama location using "https://maps.googleapis.com/maps/api/streetview?"

My problem is the following, I define the coordinates of my image using (lat_pano, lon_pano) which are, from what I have understood, the coordinates of the vehicle. But, when I check the coordinates on the satellite image and in the streetview panorama, we are not exactly at the same place (2-3 meters of shift approximately). Also, when I try to build a url with (lat_pano, lon_pano) and open a browser using this url, once the page is fully loaded, the url changes and the coordinates also, and those coordinates seem to be better located than (lat_pano, lon_pano).

Here's an example:

My coordinates : (46.563276, 3.316909) Coordinates from the metadatas request (panorama location) : (46.56322122509246, 3.316919860185686) = (lat_pano, lon_pano)

URL with those coordinates : https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=46.56322122509246,3.316919860185686

URL once the page is loaded : https://www.google.com/maps/@46.5631994,3.3169488,3a,75y,90t/data=!3m6!1e1!3m4!1s6TlniPdxCV98aICBlE0l0g!2e0!7i16384!8i8192?entry=ttu

Let's call (46.5631994,3.3169488) (lat_url,lon_url)

You can see the difference in the following aerial image:

aerial image

Red point is (lat_pano, lon_pano) and blue point is (lat_url, lon_url).

Code sample :

''' import requests from PIL import Image import io

API_KEY = "YOUR_API_KEY"
META_BASE = "https://maps.googleapis.com/maps/api/streetview/metadata?"
IMAGE_BASE = "https://maps.googleapis.com/maps/api/streetview?"

lat = 46.563276
lon = 3.316909

params_metadatas = {
        "key": API_KEY,
        "location": f"{lat},{lon}",
        }
        
response_metadata = requests.get(META_BASE, params=params_metadatas).json()

lat_pano,lon_pano = response_metadata["location"]["lat"], response_metadata["location"]["lng"]

sv = "https://www.google.com/maps/@?api=1&map_action=pano&viewpoint={},{}"

print("StreetView URL : ", sv.format(lat_pano,lon_pano))

params_img = {
        "key": API_KEY,
        "location": f"{lat_pano},{lon_pano}",
        "fov": 30,
        "heading": -7.787179920313434,
        "pitch": 0,
        "size": "640x640",
}

response_img = requests.get(IMAGE_BASE, params=params_img)

if not response_img.ok:
    raise ValueError(f"Error when getting image: {response_img}")

img = Image.open(io.BytesIO(response_img.content))

img.save("test.png")

print("DONE")

'''

What i've tried

I tried to analyse the image query answer to check if there is any location informations but I haven't found anything, I also tried to collect those coordinates from the url once the page is loaded, but I always have the url that I sent and not the one once the page is loaded.

I would like to have an automatic process to gather image and correct coordinates metadatas from my input coordinates

Help

Did someone already face this issue? Is there any way to collect the "real" coordinates of the vehicle?

0

There are 0 best solutions below