Latest Register Log In

+ Advanced Search

Local Maps

Local Maps
By
Jul 13, 2012 (Edited Mar 11, 2014)

Suppose you want to show a map of all listings within 25 miles of the person viewing the page. Assuming you already have geolocation loaded, you can do this just by placing {FUNC_MAKELOCALMAP} somewhere in a template at Admin -> Themes -> Manage Templates.

That's the simple case, but there are lots of ways you may want to tweak the appearance or function of the map. You can do so by passing parameters:
{FUNC_MAKELOCALMAP[width <,> height <,> distance <,> location <,> cutoff]}
Width and height are the pixel size of the map -- default is 500 width 300 height. The distance parameter is the number of miles (or kilometers depending on localization settings) the listing has to be within (note that the distance is computed from a specific latitude and longitude within the city, not from city limits, so you must set a distance at least as large as the radius of the city in order to get all listings within the city displayed). Location can be a city name but defaults to visitorlocation which uses the city the viewer is in. Cutoff is the maximum number of map pins to show, which is 500 by default (showing too many can lead to memory errors or timeouts).

Here's an example of a 700x350px map of 100 listings within 10 miles of San Francisco:
{FUNC_MAKELOCALMAP[700 <,> 350 <,> 10 <,> San Francisco, California, United States <,> 100]}


You can also use conditionals for fallback maps, although this can get very slow and server-intensive... example:
<IF {FUNC_HASLOCALMAPBOOL[10 <,> visitorlocation]}>{FUNC_MAKELOCALMAP[500 <,> 300 <,> 10]}<ELSE>{FUNC_MAKELOCALMAP[500 <,> 300 <,> 10 <,> San Jose, California, United States <,> 100]}</IF>


The {FUNC_HASLOCALMAPBOOL[10 <,> visitorlocation]} is a shorthand that sets the cutoff to 1 so that not so much time/memory/cpu is wasted checking if a pin exists on the map.




Description How to display a map of local listings.
Rating
Views 307 views. Averaging 0 views per day.
Similar Listings