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: ...


10

I've used Google Maps API to GeoCode data into Latitude and Longitude fields in SFDC. You then have to use a Google Maps Mashup to display the SFDC records based on SOQL queries. This was before SFDC offered Lat/Lon fields and SOQL calls for distance. Back then you had to use a bounding box algorithm with SOQL to find the records. I have opensource code ...


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

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

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

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

The issue has made it onto the Salesforce Known Issues list. here is the link It seems that if you are able to bump the version on all your classes up to 26 that might solve the problem. However If you have a lot of classes be very careful before doing this. Changing the version of your classes can have unintended consequences and break existing ...


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

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

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 ...


6

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 ...


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

Paul, any chance that you are working in an org with a Namespace (e.g. a Managed Package development org)? I created an identically-named geolocation field (Location__c) on the Account object in my org, and ran the following query, but it only worked when I prepended the namespace prefix (e.g. SFDC auto-namespace-prepending logic is not working, I guess): ...


4

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 ...


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

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

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


3

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


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

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've messed with the pilot. It's just a field type for lat/lon. Salesforce does not supply any data to you or turn an address into a lat/lon (geocoding). If you are able to populate the data, then you can use SOQL to do things like find records within X miles of another. Our app, Geopointe, can help with this kind of thing right now and includes geocoding.


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

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.


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