28

The documentation states: Distance is calculated as a straight line—as the crow flies—regardless of geography and topography between the two points. In reality Salesforce uses the haversine formula to calculate the great-circle distance between two points. For any two points on a sphere, the haversine of the central angle between them is given by ...


12

You can use the DISTANCE and GEOLOCATION formula functions to create a custom field that will calculate the distance in miles to a fixed location. Then you can use this field in your Visualforce pages as required. DISTANCE(acme_distribution__c, GEOLOCATION(37.775,-122.418), "mi") Failing that, you can do the haversine formula calculation yourself in Apex: ...


8

Automatically populating Longitude and Latitude data for the standard Billing/Shipping Address fields on Account was introduced in Summer '16, but it appears that it needs to be manually activated. The most logical explanation for why your Location records (Salesforce seems to recommend using System.Location to avoid confusion with the standard SObject ...


7

You can use a Geolocation field. It is a compound field that consists of a Longitude and Latitude. For example, if you create a custom Geolocation field called Location__c you will automatically be able to access the Longitude and Latitude in your code as follows: Location__Longitude__s and Location__Latitude__s. You can look at the Geolocation Field ...


7

No, unfortunately it's not possible without using workarounds described here: End of javascript sidebar workarounds? Note that these kind of workarounds are not supported by Salesforce and are likely to break in future versions. The Standard Edit is very restrictive and less customizable than the View is - that's one reason some of us still use the ...


7

Unfortunately formula fields cannot be viewed on the edit page layout. The only workaround I see is to override an Edit mode with a custom visualforce page. There is an Idea to turn this feature on: Read only field available on edit layout


7

This seems like a good candidate for the SOQL Geolocation support. Try something like the following to find the first 10 branches within 20 kilometers ordered by closest branches first. SELECT Id, Name FROM Branch__c WHERE DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'km') < 20 ORDER BY DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'km') ...


7

First, Geofence Notifications are not push notifications. They are downloaded and triggered upon fence transitions. Take a look at the SDK's convenience methods for should show notification (ref. Should Show Notification Listener). This method will be called whenever the SDK is going to display a notification. You will be provided the Notification ...


6

As rao said this feature is not enabled in DEs. Unfortunately it also can't be enabled by the support. But you can access parts of it with a workaround even in DEs. Here is what you'll get from the support: As discussed over the phone I informed you that unfortunately there is no way where we can enable the Maps & locations in developer edition, ...


6

Getting geolocaiton from mobile browser is easy if you are using a browser that supports it. Try below code, navigator.geolocation.getCurrentPosition(GetLocation); function GetLocation(location) { console.log(location); } Once you have got location to javascript, you can easily interact with salesforce API using javascript remoting or AJAX API. Try ...


6

Yes, this is possible without an external API using the Location class, which can be instantiated with a latitude and longitude or queried from the database. Here's the example from the documentation. // Select and access the Location field. MyLocation__c is the name of a geolocation field on Account. Account[] records = [SELECT id, MyLocation__c FROM ...


6

Update via Mark Pond for Summer '16: Automatically Get Geocodes for Addresses (Generally Available) you can set up and activate the geocode clean rules for your org. Then, geocodes are added for addresses on existing and new accounts, contacts, and leads. No, they aren't populated automatically when the other address fields are populated. You would ...


5

As of Spring '16 release, you can now use the DISTANCE function in SOQL SELECT clause so you can easily display distance in your query results. Do note, this is the haversine distance that @Daniel Ballinger already mentioned in his answer instead of "driving distance". From the release notes... DISTANCE() Support with Location-based SOQL Queries The ...


5

If your browsers support Geolocation you will be able to get this information by adding simple JavaScript to your web to Lead form, otherwise you can simply click on the below link Here is the link from very popular Google services The JavaScript would be as below window.onload = function() { var startPos; var geoSuccess = function(position) { ...


4

Sort of... Salesforce now has a DISTANCE() function which can be used in formula fields, but it is only "straigh-line" distance and not the distance you would travel is using roads. I use this in a custom formula field today to help sales agents priortize and identify Leads nearest them. One Example: Distance between two geolocation fields DISTANCE(...


4

Yes. I believe the class is part of Spring '15 update and your code is not using Spring '15 or your org does not yet have Spring '15. New Classes - Spring '15 Update


4

It is pretty straightforward to get and set. Here is some documentation which offers the following two lines: Double theLatitude = myObject__c.aLocation__latitude__s; myObject__c.aLocation__longitude__s = theLongitude;


4

The second parameter in the DISTANCE function is GEOLOCATION (with latitude and longitude parameters). Your query should look like this: ORDER BY DISTANCE(locationField__c, GEOLOCATION(account.Location__latitude__s, account.Location__longitude__s), 'km') UPDATE: Apparently Apex bind variables aren’t supported for the units parameter in DISTANCE or ...


4

As a best practice: don't do it (at least, automatically). Just because they appear to be located in a place you don't service does not mean they are in that place, or that they live there permanently. For example, what if they use a VPN, or TOR, or some aggregate connection that masks their real presence by a significant margin? What if they're on vacation, ...


4

You can't generally use merge fields in Apex (except for Dynamic Visualforce components). Instead, you'd use normal string concatenation, or my personal preference, a PageReference: PageReference endPoint = new PageReference('https://maps.googleapis.com/maps/api/geocode/json'); endPoint.getParameters().put('address', accountRecord.Billing_Address_Text__c); ...


4

Try geo_location__latitude__s && geo_location__longitude__s


4

DISTANCE & GEOLOCATION are SOQL Methods, you can't use them in apex. Thanks for your comment kurunve, so as documented here, this should work in Apex: Location loc1 = Location.newInstance(28.635308,77.22496); Location loc2 = Location.newInstance(37.7749295,-122.4194155); Double dist = Location.getDistance(loc1, loc2, 'mi');


3

As per the official docs maps and locations are not enabled for developer orgs. https://help.salesforce.com/HTViewHelpDoc?id=customize_maps.htm Maps and Location Services | Salesforce Maps and Location Services Available in: Professional, Enterprise, Performance, and Unlimited editions.


3

To opt in you need to go to Setup | Build | Customize | Maps & Location | Settings. There is a legal disclaimer and you can set enabled to true. http://blog.sonomapartners.com/2014/11/spring-15-maps-opt-out.html


3

Just a footnote - bind variables in GEOLOCATION are coming in Summer 15 https://developer.salesforce.com/releases/release/Summer15/queries


3

Binding a variable requires a colon to start the binding. The correct syntax for your function would be: public void getLocalSites(Decimal lat, Decimal lon, integer dist) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT Name, Start_Date__c, End_Date__c, ID FROM SiteProgram__c Where End_Date__c ...


3

I agree it is curious there is no obvious way to make this appear in the UI. So for now it is workarounds. Visible is easy. A workaround could be to create a formula field that took the Lat/Long values and simply displayed them in string format. TEXT(BillingLatitude) & " , " & TEXT(BillingLongitude) To have them editable, there are a few ways, ...


3

Unfortunately, according to the documentation, you can't do that: Location-based queries are supported in SOQL in Apex and in the SOAP and REST APIs with the following limitations: DISTANCE and GEOLOCATION are supported in WHERE and ORDER BY clauses in SOQL, but not in GROUP BY or SELECT. Referenced from here You can then go through the list and calculate ...


3

The other option is to fetch the public IP of user and from that IP figure out the location(approximate) of user. Here is how you can find the users Public IP using javascript: $.getJSON("http://jsonip.com?callback=?", function (data) { alert("Your ip: " + data.ip); }); http://jsfiddle.net/lesson8/juJYJ/ Then use a free open source community that ...


3

We use navigator.geolocation.getCurrentPosition() in a Lightning for Communities app with LockerService enabled. Here's some sample code you can use to prove that it works within LockerService. Set up an init handler in your component, then add this to your controller. // asks the user to get the location of their browser doInit: function(component, event, ...


Only top voted, non community-wiki answers of a minimum length are eligible