Life without GPS: Bing Maps API

Bing Maps provides a REST API for creating a static map with pushpins, geocoding an address, and creating routes. There are a plethora of options available for Microsoft lovers (http://msdn.microsoft.com/en-us/library/dd877180.aspx) ranging from Ajax controls to iOS controls for using Bing Maps in your application. We will, however, use the REST API to determine the user's location (when Wi-Fi and cellular radio is not available to determine location).

Specifically we will use the Bing Maps API to convert a user address into location; this process is known as geocoding, as described earlier. Bing Maps uses these coordinates to plot the locations on a map. The Bing Maps API provides an option for both geocoding and reverse geocoding.

To illustrate a simple REST API call from the Bing Maps API that finds location by a given address, see http://msdn.microsoft.com/en-us/library/ff701715.aspx. The Geocoding API is consumed by the following API call:

http://dev.virtualearth.net/REST/v1/Locations/US/adminDistrict/postalCode/locality/addressLine?includeNeighborhood=includeNeighborhood&key=BingMapsKey, where the output can be either JSON or XML, and the parameters can be either of the following:

Parameters

Description

adminDistrict

Typically a US state.

postalCode

US zip code.

Locality

City name.

addressLine

Street address.

includeNeighborhood

For including neighborhood data in response. This value can be either 0 or 1.

BingMapsKey

Key obtained from https://www.bingmapsportal.com/.

An example geocoding request for Microsoft Corporation office at Mountain View, San Francisco, CA, USA is constructed as:

http://dev.virtualearth.net/REST/v1/Locations/US/CA/94043/San Francisco/1065 La Avenida St?o=xml&key=xxxxxxxxxxxxxxxx, where xxxxxxxxxxxxxxxx is the Bing Maps API key you obtained from https://www.bingmapsportal.com/. This API call returns the following results:

Life without GPS: Bing Maps API

Our interest lies is in the<Latitude> and<Longitude> XML nodes, which hold the location value for the address we specified. If you do not have the exact address, you can use the Find a location by Query API call of the Bing Maps API, where the input can be any query string. Depending upon your app's targeted region, construct the right REST call. As they say, "Read the documentation carefully".

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.148.105