Geolocation for Mobile AppsIn Summer ’12, a new pilot program feature is introduced to support Geolocations. The new composite field type, geolocation, consists of two components: longitude and latitude. It is specifically designed to hold the geo-coordinates of a location for any objects, most commonly address related objects, such as Contact, Account, restaurants, shops, etc. When a geolocation field is added to these objects, and coordinates are set, users can perform radius based search. Some examples: to find the records of restaurants within 5 miles of my current location, to find all the homes within 15 miles of a sports arena, etc.

Geolocation for Mobile Apps

Mobile applications will find this new feature especially handy for providing mobile location-based search on Salesforce objects. Just like a regular custom field type, the geolocation field can be added to an object through object setup wizard. Decimal point precision can be set. Users have the choice to display coordinates in decimal point or degree, minute, and second notations. List views for objects with a geolocation field have a WITHIN operator to conduct radius based searching and filtering. You can perform distance calculation between two geolocation points using the DISTANCE(loc1, loc2, distance_unit) function inside formula fields.

Also, SOQL is enhanced with DISTANCE and GEOLOCATION functions that let you write SOQL queries to perform location-based searches. For example, to find the names and phone numbers of all restaurantswithin 1 mile of 1 Market Street, San Francisco, California, which has a geo coordinate of 37.794915,-122.394733, you can write a SOQL query as:

SELECT name__c, phone__c
  FROM restaurant__c
 WHERE DISTANCE(loc__c, GEOLOCATION(37.794915,-122.394733), "mi") <= 1

The Geolocation pilot is currently limited to Sandbox and Developer Edition orgs with Summer ’12. To request access to the pilot feature, please contact salesforce.com support and request to participate in “Geolocation Field Type Pilot program.”

Enter the Mobile Developer Challenge!

Take what you’ve learned from this post, use it to build your own mobile app, and then enter it in our Mobile Developer Challenge for a chance to win some serious cash!

tagged , , Bookmark the permalink. Trackbacks are closed, but you can post a comment.
  • Wes Nolte

    Eeeeepic!!1!!

  • Abhinav Gupta

    Great feature specially when most of the apps are becoming social, and geo aware.

  • http://twitter.com/zachelrath Zach McElrath

    Total awesomeness.

  • Nisha Agrawal

    very intresting , cool & useful feature. dying to use it…

  • http://www.facebook.com/vasuneet Vasuneet Arya

    What necessary field (related to location like zipcode or longitude latitude ) will be required which must be in restaurant__c custom object.
    regards
    Vasuneet Arya

    • Jack Cai

      the only fields required for this SOQL to works are the fields listed in the statement, i.e., name, phone, and loc.

    • Anonymous

      the only fields required for this SOQL to works are the fields listed in the statement, i.e., name, phone, and loc.

  • William Goulding

    Brilliant feature! I’m already thinking of how much easier this makes things!

  • http://twitter.com/C0lemab Anthony Coleman

    Very good idea. Time for me to revise the geocoding engine I wrote: http://www.forcedisturbances.com/2012/03/caching-data-from-googles-geocoding.html

  • http://twitter.com/rbklaassen Ronald Klaassen

    Just got the feature enabled in my developer org. Created a Geolocation field on Account, filled two accounts with geolocation values and created a test to get the accounts within 10 mile in a VF page. The code of the class:
    [code]
    public with sharing class GeolocationTestController {

    public GeolocationTestController(ApexPages.Standardcontroller stdCont) {
    Account[] accountsNearby = [SELECT Location__c, Location__latitude__s, Location__longitude__s, Id, Name
    FROM Account
    WHERE
    DISTANCE(Location__c, GEOLOCATION(37.794915,-122.394733), 'mi') <= 10];
    }

    }
    [/code]
    Which saves perfectly. But when I embed a VF page with this class as extension I get this error:
    Content cannot be displayed: Object type not accessible. Please check permissions and make sure the object is not in development mode: java.lang.UnsupportedOperationException null

    Anybody got an idea on this?

    • http://twitter.com/sjorg Scott Jorgensen

      Did you double-check the field-level security on that new geolocation field you created? Maybe your profile can’t see it? Or maybe the version number for the API on your Visualforce page needs to be incremented up to the next version?

    • http://twitter.com/sjorg Scott Jorgensen

      A colleague sent me a better suggestion:

      Remove location__c from SELECT, location field is not yet supported in SOQL

  • William Goulding

    Does anyone know if there are any official docs on these features? Appreciate it’s only in pilot, but it’s all bit “stabbing in the dark” at the moment…

    • Jack Cai

      Unfortunately, no official doc is available for pilot. Usage is actually quite simple.

      You add location field just like any other custom field.

      two functions are provided:

      LOCATION(lat, lng), and DISTANCE(loc1, loc2, “km”/”mi”)

      component reference suffix is __s, for example, if you have a loc field,

      you can use loc__Latitude__s, and loc__Longitude__s to get the latitude and longitude of the loc field in formula and in SOQL/Apex

      Some caveats for pilot release

      1. ORDER BY is not supported
      2. SELECT works on component levels only, i.e., SELECT loc__Latitude__s FROM object works, but SELECT loc__c FROM object does not
      3. DISTANCE function in WHERE clause needs to be strictly in the format of DISTANCE(loc__c, GEOLOCATION(, <lng), "mi"/"km") in which loc__c is the field of the object, and GEOLOCATION(, ) is the literal form of a geo location point

    • Anonymous

      Unfortunately, no official doc is available for pilot. Usage is actually quite simple.

      You add location field just like any other custom field.

      two functions are provided:

      LOCATION(lat, lng), and DISTANCE(loc1, loc2, “km”/”mi”)

      component reference suffix is __s, for example, if you have a loc field,

      you can use loc__Latitude__s, and loc__Longitude__s to get the latitude and longitude of the loc field in formula and in SOQL/Apex

      Some caveats for pilot release

      1. ORDER BY is not supported

      2. SELECT works on component levels only, i.e., SELECT loc__Latitude__s FROM object works, but SELECT loc__c FROM object does not

      3. DISTANCE function in WHERE clause needs to be strictly in the format of

      DISTANCE(loc__c, GEOLOCATION(, ), “mi”/”km”) in which loc__c is the field of the object, and GEOLOCATION(, ) is the literal form of a geo location point

  • Anonymous

    Unfortunately, no official doc is available for pilot. Usage is actually quite simple.

    You add location field just like any other custom field.

    two functions are provided:

    LOCATION(lat, lng), and DISTANCE(loc1, loc2, “km”/”mi”)

    component reference suffix is __s, for example, if you have a loc field,

    you can use loc__Latitude__s, and loc__Longitude__s to get the latitude and longitude of the loc field in formula and in SOQL/Apex

    Some caveats for pilot release

    1. ORDER BY is not supported
    2. SELECT works on component levels only, i.e., SELECT loc__Latitude__s FROM object works, but SELECT loc__c FROM object does not
    3. DISTANCE function in WHERE clause needs to be strictly in the format of DISTANCE(loc__c, GEOLOCATION(, <lng), "mi"/"km") in which loc__c is the field of the object, and GEOLOCATION(, ) is the literal form of a geo location point

  • http://twitter.com/genebike Gene-Michael Koopman

    This looks interesting and useful, however I just want to confirm some thing first: The functionality above, is for querying against/with and storing location data. The actual population of such data is still the responsibility of the customer, i.e. SFDC has not yet introduced any native location data service tied to the above functionality.

    • Anonymous

      Correct.

    • Matt DeTroia

      There are applications on the AppExchange that provide this capability. We used the Google API and Esri API for geocoding and found the Esri API to be much more accurate for both Batch and Live geocoding and the license terms are much more clear and easy to leverage.

      • Anonymous

        Currently, the geolocation feature only supports the object model for geolocation, i.e., field types and its related constructs and distance functions, and associated facilities that come with custom schema, e.g., REST API, listview, reports, etc. (some of them will be supported at GA). No GeoCoding function is supported

      • K Arun

        HI. I am looking to do ESRI clickable functionality in Visualforce.

        Please Help me and Is there any possibility to do it?.

  • http://twitter.com/avinashmunaga Avi

    I am not able to add any field of type geolocation in any object. How to have an object of type geolocation in an sObject say Account to perform queries having distance and geolocation functions.

    Please suggest. Looking for help desparately.

    • Anonymous

      Did you contact Salesforce to have the perm turned on?

  • Amin Mufti

    We would like to calculate the distance between two points, per :”You can perform distance calculation between two geolocation points using the DISTANCE(loc1, loc2, distance_unit) function inside formula fields”.

    We could not get this function to work. It seems [DISTANCE(loc__c, GEOLOCATION(37.8,-122.3), "mi")] only support after [Where].
    If we put [DISTANCE(loc__c, GEOLOCATION(37.7,-122.3), "mi")] after [Select] as a select value, the syntax error will appear.

    Are we missing something