Store Locator using FreeHound and Bing Maps V.7
The example provides an overview of how to design a page to incorporate a FreeHound Proximity API along with Bing Maps API in order to create a simple store locator. It does not describe the full JavaScript used, but ensures you know how to link the APIs correctly and how to set your page up to include an interactive map.
Header
Firstly, you need to include a link to FreeHound Proximity API in header of your page:
Please note that you need to replace the key ‘xz396aw1qe432q1′ value with an API key provided by eHound.
Now you can include a link to Bing Maps API in header of your page:
The code
For the purpose of this demo, only the FreeHound API calls will be explained here. For references to Bing Maps API please view documentation on Bing Maps AJAX Control, Version 7.0
Firstly you need to instantiate FreeHound object and specify the name of callback function. This function will be called after proximity search has been performed and will allow you to manipulate the results in appropriate manner.
Now you will need to instantiate FH_Search object that will allow you to add parameters to your search.
search.count = 10; //number of locations to be returned in the result set
search.max_distance = 0; //distance limit for proximity search in km, 0 for unlimited
search.point = new FH_Location( new FH_LatLon( latitude,longitude ) );
‘count’ parameter must be an integer between 1 and 100. It specifies the number of results to be returned
‘max_distance’ parameter must be a positive integer. It specifies the maximum distance for search
‘point’ parameter is an object that allows you to specify latitude and longitude coordinates of your initial search location
You can also add optional filter parameter to limit search only to specific category:
search.filters.push( new FH_SearchFilter(‘cat_id’, ‘eq’, ’177′) );
Note: at this stage filtering can only be done on category ID.
This will limit the search to category with ID 177. (You can find ID of the categories in your account under categories section in myHound)
You then can call the method to perform the proximity search:
Now in your callback function [in this example in function showLocs(response)] you can loop through the result set returned:
if ( response.error_code ) {
alert(response.error_message);
}
if ( response.record_set ) {
for (var record_count = 0, rl = response.record_set.length; record_count < rl; record_count++ ) {
var record = response.record_set[record_count];
…
}
}
}
Record Set Available Attributes
View Available Attributes Here
Be the first to comment.