API Options

Parent Previous Next

Using the undermentioned API options you can fetch data from an external data source. For ex, if you have already have a listing database with latitude and longitudes, you can use it with this script.

1) JSON listings data source URL: You can fetch listings from an external database to this script. In order to do so, you'll need to write a script that reads data from your external database and outputs data in JSON format. The required JSON format is:


Here la is latitude and lo is longitude.  The above mentioned data should be wrapped in jQuery callback function which is dynamically sent to your URL. So for ex, if your your custom script is in php then it should print the data, in this format:

print $_GET['callback'].'('.[{"la":"43.589","lo":"-79.6441"},{"la":"43.6915","lo":"-79.5091"},.....].')';

Please look at an example file name 'jsonDataTest.php' provided with this script. The function getMarkersJson2() returns data in JSON format i.e. [{"la":"43.589","lo":"-79.6441"},{"la":"43.6915","lo":"-79.5091"},.....] and then we wrapped it with the callback function before outputting. The classified script can support 10s of thousands markers without any problem.

Following GET parameters will be sent to your URL from the search form: category, subcategories, price, requery, city. So you can fetch them like this:

$_GET['category'] :  The category selected in the search form.

$_GET['subcategories'] : Selected subcategories separated by a comma, for ex: Activities,Classes,Events

$_GET['price'] : Selected price range without the currency sign, for ex 400-800

$_GET['requery'] : Specific query entered by the viewer in Keyword/Street/ID/Postal text box.

$_GET['city'] : The city name entered in the city text box on the search form.

So its upon your custom function to fetch these parameters and output latitude, longitude data based on this search criteria.

2) JSON marker data URL: This is the url of the page which should return marker data when a marker is clicked and the data returned by your URL is shown in the marker balloon. The data outputted should be in json format and wrapped in jQuery callback function as mentioned above. Following GET parameter is passed on to the external URL: latlng . Your script can use it to query your database for the listing/s at this particular latitude and longitude.

$_GET['latlng'] : latlng will have latitude and longitude separated by comma, for ex: 43.6548,-79.5642 . Please look at the provided example file name ajaxTest.php

The output data can contain html too but as mentioned above, the entire data should be json encoded before outputting. In php it can be easily done i.e. you can convert a string of data to json encoded string using json_encode function. You can output multiple listing data, If there are multiple listings related to same latitude and longitude. You custom function will have full control on how you want the marker pop to look like. So in our example php file, we use a function markerData to fetch the data related to the provided latitude, longitude.

print $_GET['callback'].'('.$markerData[0].')';

so the output for a single marker pop looks like this:

$_GET['callback'].("This is the marker data related to the coordinates: 43.6548,-79.5642").')';

or even return complex html data, for ex:

$_GET['callback'].("<div class='markerInfo'  ><h4>Praesent ac nisl eu mi viverra posuere eu at ante. Ut sem leo, ultrices sed vestibulum vitae, adipis<\/h4><font style='font-size:85%;'><b>Community - Volunteers<\/b> (#20), <b>Phone:<\/b> 123-456-7890, <b>Address:<\/b> 1234 Sample street, <b>City:<\/b> Etobicoke<\/font><br \/><div class='mapInfoText' style='float:left; width:70%; padding:10px 10px 0 0;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In placerat accumsan enim ac aliquam. Etiam vitae nibh eget ante pellentesque posuere. Cras odio nunc, interdum vel semper vitae, posuere eget metus. Fusce ac tellus nulla, et pharetra magna. Duis sit amet pellentesque magna. Vestibulum vel arcu nisi, vitae sodales nulla. Maecenas fringilla d.... <br \/><a class='btn pull-right' style='margin-top:5px;' target='_blank' href='index.php?ptype=viewFullListing&reid=20'>Direct Link<\/a> <a class='btn btn-info pull-right' style='margin-top:5px; margin-right:5px;' href='#' id='theListingLink'><span id='20'>More Info<\/span><\/a><\/div><div class='mapInfoPic'><a href='gallery.php?adid=20'><img height='120' src='timthumb.php?h=120&src=http:\/\/www.codiator.com\/real-estate-made-easy\/uploads\/scottwills_city_1328159416.jpg' \/><\/a><\/div><\/div>").')';

As you see the above data is json encoded so it automatically escapes the data. The data outputted by your custom URL would be shown in the marker balloon of the clicked marker. If you also want to implement 'More Info' button, which when clicked shows a dynamic page over the map, you'll need to make sure that the link has the following format:

<a href='#' id='theListingLink'><span id='20'>More Info</span></a>

The <a element should have the id='theListingLink' and <span inside it should have the id of the listing in question. For ex, here the id=20' means that we want to fetch listing #20 when 'more Info' link is clicked. The listing id would be passed to the URL mentioned below.

3) JSON full listing data URL: This is the url of the page which should return data for a particular listing identified by id returned by 'More Info' link as mentioned above. This is optional, i.e. if you don't want to implement 'More Info' button/link. The data returned is shown in the dynamic page which is shown above the map when 'More Info' button is being clicked. Please look at the test file name listingJsonTest.php which outputs the entire listing content in JSON format for the listing identified by id in an external database.

print $_GET['callback'].'('.getMapListingTest($_GET['id']).')';

The function getMapListingTest($_GET['id']) returns the json encoded data for the listing identified by id.

Created with the Personal Edition of HelpNDoc: Create HTML Help, DOC, PDF and print manuals from 1 single source