4
votes

I am using the static image API (where you pass a URL to Google and it returns an image). My issue is the images google is returning are sometimes not straight-on/clear view of the address. I am looking to get the same image as what the Google Maps search feature comes up with as a thumbnail.

I have read the Google Documentation for this API. An example URL is: https://maps.googleapis.com/maps/api/streetview?parameters&size=640x640&fov=50&location=4113+Hartford+Dr+Garland+TX

If I put this same address (4113 Hartford Dr, Garland, TX) directly into Google Maps, I get a much cleaner image.

I have experimented with changing the FOV value. My only other idea is to use heading, but I am unsure about this.

The end implementation is in Excel using VBA.

Let me know if you need any additional information.

1
stackoverflow.com/questions/16111626/… is similar, didn't see a clear answer here though. - Shawn007
I tried adding heading. It's almost the same result, anyway it works and you can pinpoint the heading. maps.googleapis.com/maps/api/… - Emmanuel Delay
Would you just always use 180? Any logic behind this? - Shawn007
No, I checked the location on Google Maps, searched the camera (vantage point). The house was due north. 180 is pure accidental - Emmanuel Delay

1 Answers

3
votes

You are going to have to compute the heading. I don't have the raw math for that, but here is an example using the JS API, if that's an option.

  function getStreetView(lat, lng) {
    let panorama = new google.maps.StreetViewPanorama(
      document.getElementById('panorama'), {
      position: {lat: lat, lng: lng}
    })
    let service = new google.maps.StreetViewService
    service.getPanoramaByLocation(panorama.getPosition(), 50, function(panoData) {
      if (panoData) {
        let panoCenter = panoData.location.latLng
        let heading = google.maps.geometry.spherical.computeHeading(panoCenter, {lat: lat, lng: lng})
        let pov = panorama.getPov()
        pov.heading = heading
        panorama.setPov(pov)
      } else {
        alert('no streetview found')
      }
    })
    map.setStreetView(panorama) // set dude on map
  }