Finding Latitude / Longitude with Bing
I was recently commissioned to develop a series of upgrades to an admin system. An aspect of those upgrades included providing a mechanism for the user to obtain latitude and longitude values for any given UK address.
"Piece of cake," I thought. That was until I was told that instead of using my current favourite maps API in the form of Google Maps, I had to use Bing / Multimap instead.
Having never played around with the Bing API before, I delved into the documentation and examples. Whilst not being as easily accessible or thorough as the Google Maps documentation, I was able to produce a script that does exactly what the specification required: return latitude / longitude values for any given UK address.
HTML / PHP
First, I built a form whereby the user could input address details. The documentation stated that you can break down these details into constituent parts, namely: addressLine, locality, adminDistrict, postalCode and countryRegion.
In addition to the form, I also required two containing divs to be present to display the generated results from my query to the API.
I also added some styles to my page to prevent certain aspects of the produced map from displaying, such as the copyright notices, scale bar, compass and map type selectors.
Initially, as there are no elements present in the form, a blank map of the UK is produced. To actually generate the map takes only a couple of lines of code. One to instantiate the Maps class, one to pass your API key, and one to centre the map over a particular area.
Conclusion and Demo
In my opinion, Bing maps are nowhere close to replacing Google Maps as my API of choice. However, playing around with the API has opened my eyes to an alternative, which does seem to be fairly easy to use and implement.