When it comes to property searches, nothing tells you that you’ve arrived at the right house like a picture of the front door. If you need these property photos for your web applications, you have a few options. You can go door-to-door and snap pictures yourself. This is good and cheap if you only have a few houses to snap, but it doesn’t scale well. You can also hire somebody to drive around and either take photos or video of properties for you, and hope the resulting photos are in a format you can use. Or, you can tap into a billion-dollar company who has racked up so many millions of miles driving up and down every street, their odd cars are barely noticed anymore.
Many developers and geospatial people are familiar with Google Maps and Google Street View. Not only can we find out where we are going, but we can see what it should look like when we get there. Of course, the images aren’t up-to-the-minute, but they’re good enough for most uses.
In the older days, to see the street view images, you had to load the Google Maps API, load a start location, and create a StreetViewPanorama. Downloading the Google Maps API and waiting for the panorama to load can take up considerable time, especially on a mobile device. Thankfully, Google has provided a shortcut.
Google Street View Image API
<img src="http://maps.googleapis.com/maps/api/streetview?location=41.947372,-87.65641&heading=-696.966386554622&pitch=25.71428571428571&fov=90&size=640x480" alt="Wrigley Field" />
The code above translates to the image at the top of the page. That’s all you need to show a Street View image without the hassle of another library to load.
The Google Street View API has multiple parameters it uses to return a Street View image, including:
- key (optional) – API key to remove use limits (and charge you appropriately)
- location – point where the view starts, either as lat/long, or an address
- heading (optional) – 360 degree direction the camera is facing (0 = North)
- pitch (optional) – 180 degree vertical direction, with 0 = straight ahead and 90 looking up
- fov (optional) – field of view, with a number range from 10 to 90. FOV describes how wide or narrow the view is. A smaller number appears to zoom into the image more.
- size – the width and height of the image requested in pixels, with an “x” to separate the values (max 640×640)
The important field in this list is location, because it can accept more than just a latitude and longitude. The location parameter can also accept a string address, like “1313 Mockingbird Lane, Hollywood, CA”. Of course, you need to properly encode the URL of the image to properly encode commas and spaces. Using that example, this code:
<img src="http://maps.googleapis.com/maps/api/streetview?location=1313%20Mockingbird%20Lane,%20Hollywood,%20CA&fov=90&size=360x280" alt="1313 Mockingbird Lane, Hollywood, CA" />
The Street View Image API requires the API key for high volume use, but low volume websites can get by without it. Without the key, a website user can see up to 25,000 images during the day from the same client IP address (with smaller caps by the hour and minute). Over the limit, and the client will see an image showing they exceeded their limit.
The Bad News
Like any story that’s too good to be true, there’s always a catch. In this case, the location you request isn’t always the picture you want. A vast majority of the photos retrieved with a location address will return the front of a property. However, some will return something unexpected, such as a different building, the side of a building, or even the inside of a building.
You can’t really be sure when you’re going to run into these unusual situations. From my observations, side views of the houses tend to show up on properties located on corner lots, where Google picks a camera shot from a side street, because it’s closer to their address point. Wrong locations can typically be traced to incomplete addresses, such as forgetting a street direction, or not including the city and state. As for inside shots, well, there is a proposal to filter street view images by outdoor only, but that feature is still in the works.
For those unique situations where Google doesn’t get it right, I propose a solution. Instead of relying solely on the address to fill in the location parameter, be prepared to fill in an entire alternate image URL with a corrected view. Be prepared to fill in the whole URL with your code, either using a blank image when people request you redact their property photos, or enter in an entirely new Street View Image API url with the appropriate lat/long, heading, and pitch to show the property in the best light.
You can determine that corrected view using an online tool I call A Better StreetView. It lets you experiment with the URL parameters in Google Street View to get the best View. You can enter an address in the location blank, see what photo comes up in the Street View Image. If you’re not satisfied with the image, you can also feed the address to Google Maps and Google Street View, where you can pan and tilt the Street View camera angle until you get the view you want.
Knowing the features and limitations of the tools we have at our disposal, we can create something great.