best grammar app

Creating Location Aware GPS based BPM Applications: Free Download Code

Submitted by Abhishek on Fri, 2012-06-01 18:25
Google Maps

GPS of Global positioning system can be used to determine the current location of the user. A number of BPM projects have the requirement to gather the coordinates of the user to figure out what localization or personalized services can be provided.

Here are some use cases

  • You need to determine the location of the user who originated the request
  •  Based on Origination of request determine whom to route the task to
  • Give a Map to user (defaulted to current Location) where he can choose Location (From and To)
  • Initiate a workflow if the user reaches a particular location
  • Gather the location where a Package was handed over to the Customer

 

.. and many more.

Lets understand some concepts before going into implementation

  1. Modern Mobile Phones /Smartphones come with a GPS Device
  2. Device GPS Uses Satellites to determine location of a user
  3. Cellphone data/WiFi network /IP Address can also be used to determine user location (Using a method of triangulation)
  4. Newer browsers are starting to support the W3C Geolocation standard. This standard is part of HTML5 specfication and can be used easily

Believe it or not, you can determine user location even if he does not have a GPS Device. This is done using a method available in modern browsers like Safari, Firefox. Again this means even Locations of desktop machines can now be determined. It may not be accurate but good enough in most of the cases. There could be some cases in which the determination is way off. So do some testing before giving it to your users.

We want to develop a generic solution. Fortunately you can determine user location using just JavaScript!!

To get started, first find the Google Maps library. It comes with Geo Location API’s with which you can do it.

 

Step 1: Create a Simple HTML Page

Create a simple HTML page  like this

<html>

<head>

<title>GPS BPM Test</title>

<body>

</body>

</html>

 

Step 2: Add Google Maps Geo location library

You will need to ad the line below in your <head> tag to include Geo Location in your Project.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>

Note the parameter “sensor=true” in the code. This is used to indicate the logic that if a GPS Sensor is available on the device use it. This is useful if you are accessing this web page from a Mobile Device/Smartphone or a tablet. If you specify “false” then the triangulation method is used.

When the user loads the page, he would get a confirmation like below

 

 

 

Step 3: Add an Initialize method

Add a initialize method which needs to be called when the geolocation API’s get loaded successfully.

<bodyonload="initialize()">

 

Step 4: Add code to get the location

Now in your initialize method add code to get the location of the user

<script>

function initialize(){

if(navigator.geolocation) {

   navigator.geolocation.getCurrentPosition(function(position) {

      alert(position.coords.latitude+”/”+position.coords.longitude);

     

    }, function() {

      alert(“Unable to determine location”);

    });

  }

}

</script>

The Object navigator.geolocation can be used to determine the location. The call

navigator.geolocation.getCurrentPosition()

Once the location is determined, the function as the first parameter is called. To  it the position variable is passed with which you can get coordinates

  • Latitude: position.coords.latitue
  • Longitude: position.coords.longiture

That’s it, Now you can use this data to update form fields, pass through ajax and much more. If you open the page in a browser you will see an alert like this

 

If you are using it on a mobile browser with a GPS device, you get the coordinates accurately.

To Download the Code Click here

Hope this helps. Questions and suggestions are welcome.


Abhishek Mishra
Good experience in working with BPM technologies like Savvion, JBPM. Founder and Chief Editor of BPMGeek.com. Founder of Savvion Business Manager Mobility Framework Savmobify| View my BPMGeek Profile
|
best grammar app

About BPMGeek

BPMGeek is an initiative to collaborate and communicate with the growing Business process management community out there. The goal is to help developers connect with experts, ask questions, post their learning and get understanding of BPM Concepts. Often tool specific knowledge of niche areas end up developers perplexed and confused - especially when there are very less number of resources available. We will be coming up several several new features. Have a look at our Roadmap here

BPMGeek is an independent entity not associated with any Product. All BPM product professionals are invited to contribute. The Logos and Names used across the site belong to their respective owners. The viewpoints mentioned by Individual contributors are their own. BPMgeek cannot be held liable for any issues arising out of it.


BPMgeek is promoting the Nounshoun English Grammar App - developed by Constellation Software.