Created
February 3, 2014 21:53
-
-
Save cfalzone/8793213 to your computer and use it in GitHub Desktop.
Using the aquent geolocation tool in dotCMS to compute the nearest office location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## GET THE LOCATION DATA MAP FOR THIS IP | |
#set($userLocationMap = $geoip.getLocationMap($ip)) | |
## GET THE LOCATION DATA OBJECT FOR THIS IP | |
#set($userLocationObj = $geoip.getLocation($ip)) | |
## TRY TO GET THE CLOSEST MARKET | |
#set($marketDistance = 100000) | |
#set($nearestMarket = 0) | |
#foreach($office in $dotcontent.pull("+structureName:aquentOffices +categories:${userCountry.toLowerCase()}* +languageId:1",0,'')) | |
#set($officeDistance = $geoip.distance($userLocationObj, $text.getFloat($office.lat), $text.getFloat($office.long))) | |
## ONLY RUN IF WE COULD CALCULATE A DISTANCE | |
#if($UtilMethods.isSet($officeDistance) && $officeDistance < $marketDistance) | |
## EXTRACT MARKET ID FROM THE OFFICE LOCATION CATEGORY KEY, THE toInteger() TRIMS LEADING ZEROES | |
#set($nearestMarket = $math.toInteger($office.location.get(0).key.substring(5))) | |
## JUST A CATCH IN CASE THE FIRST CATEGORY IS FOR 'ALL MARKETS' | |
#if($nearestMarket == 0 && $UtilMethods.isSet($office.location.get(1).key)) | |
#set($nearestMarket = $math.toInteger($office.location.get(1).key.substring(5))) | |
#end | |
#set($marketDistance = $officeDistance) | |
#end | |
#end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment