When presenting custom location data in Bing Maps applications, a frequent requirement is to geocode the addresses of your location data prior to presenting them on the map, ensuring that you have latitude and longitude coordinates that accurately reflect the real-world locations. Bing Maps offers batch geocoding capabilities via the Bing Spatial Data Services Geocode Dataflow API, and also via the Bing Maps Account Center, enabling data sources containing addresses to be geocoded en masse.
Occasionally, however, some addresses may not get geocoded as precisely as desired. Reasons for this can include incomplete or inaccurately captured address data, the use of ‘vanity’ addresses, and more. In these instances, being able to specify the precise location of addresses via a map-based utility can be very beneficial. Administrators can leverage the accurate base maps and rich imagery available in Bing Maps to identify the correct location, and capture the corresponding latitude and longitude.
For data sources that are managed via the Bing Maps Account Center, this ability is built into the Entity Data Editing interface. Many implementations take an alternate architectural approach, however, and host the location data in another location, such as SQL Azure, or an on-premises database.
This post includes a utility built with the Bing Maps AJAX v7 map control and Bing Maps REST Services to allow us to obtain accurate longitude and latitude coordinates via a map-based interface, with the ability to:
- geocode address data and visualize the resulting geocoding metadata
- visualize coordinates on maps and imagery
- refine pushpin locations by dragging them with our mouse
- save resulting pushpin coordinates to our data source
Download the source code for the application, unzip it, and enter your own Bing Maps key in the placeholder on line 66. Now open the HTML page in a web browser:
Using the Utility
The utility can be used as-is to achieve a number of geocoding tasks. You can enter an address or place name into the ‘Geocode Address’ input box. The input text will be geocoded via the Bing Maps REST Services Locations API, and any geocoding matches found will be displayed as pushpins on the map.
Click any of the pushpins to view the metadata about the geocoding match. You can view the type of Entity the result represents, the confidence of the result, any returned match codes, and the calculation method used to derive the coordinates. Insight into what each of these attributes represents can be found here. The latitude and longitude of the pushpin are also displayed.
You can drag any of the pushpins with your mouse to move them to a new location. If you do this, you will see the coordinates of the new location reflected in the infobox, along with an alert that the pin has been dragged. By doing this, you can achieve a ‘rooftop-level’ precision, even for addresses which are not able to be geocoded to this precision level via the Locations API. You can also drag the pushpin to the desired location on larger properties, such as the main entrance of a large retail property or hotel.
If you have existing coordinates, you can enter them into the ‘Latitude’ and ‘Longitude’ input boxes, and assuming the coordinates entered are valid WGS84 decimal coordinates, the location will be displayed with a pushpin.
You can also simply navigate the map to your desired location, and CTRL + left-mouse-click to place a pushpin at that location.
At any time, you can open up the infobox for any pushpin, and select the Reverse Geocode action, which will use the Bing Maps REST Locations API to get location information associated with the current latitude and longitude of the pushpin.
Customizing the Utility
The utility can be extended to integrate more seamlessly with your data source or database. Possible extensions include:
- Dynamically retrieving source address or coordinate information for existing location records directly by ID or attribute. This would enable administrators or other users to visualize the coordinates of existing records based on incoming issue reports
- Customizing the handler function associated with the Save Data action in the infobox. This function can be adapted to save the updated information directly to the data source or database
While the batch geocoding capabilities of Bing Maps Spatial Data Services can meet most geocoding requirements for address data in locator-style applications, having a tool that can help you easily fine-tune location coordinates can help you ensure accuracy of data for end-users.
The source code for the application can be found here.
– Geoff Innis, Bing Maps Technical Specialist