Revisions
-
joshbirk created this gist
Oct 8, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ <apex:page StandardController="Contact" showHeader="true" sidebar="false"> <script> var pos = {}; function success(position) { pos = position.coords; console.log(pos); } function error(msg) { console.log(msg); } if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success, error); } else { error('not supported'); } function setPos() { var inputs = document.getElementsByTagName('input'); for(var x = 0; x < inputs.length; x++) { if(inputs[x].id.indexOf('contactlat') >= 0) { inputs[x].value = pos.latitude; } if(inputs[x].id.indexOf('contactlong') >= 0) { inputs[x].value = pos.longitude; } } } </script> <apex:form > <apex:pageBlock> <apex:pageBlockButtons> <apex:commandButton action="{!quicksave}" value="Save"/> <button onClick="setPos(); return false;" id="setPosBtn">Set Position</button> </apex:pageBlockButtons> <apex:pageBlockSection title="My Contact" columns="2"> <apex:inputField value="{!Contact.FirstName}" /> <apex:inputField value="{!Contact.LastName}" /> <apex:inputField value="{!Contact.Location__Latitude__s}" id="contactlat" /> <apex:inputField value="{!Contact.Location__Longitude__s}" id="contactlong" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ public with sharing class GeoContactController { public GeoContactController() { } public GeoContactController(ApexPages.StandardController stdc) { } @RemoteAction public static List<Contact> getNearbyContacts(Decimal clat, Decimal clong) { String q = 'SELECT Name FROM Contact WHERE DISTANCE(Location__c, GEOLOCATION('+String.valueOf(clat)+','+String.valueOf(clong)+'), "mi") < 10'; List<Contact> contacts = Database.query(q); return contacts; } }