With the new rich HTML text area in Spotfire it is possible to get the user location while the user is looking at the analysis in a consumer or business author mode (basically in a browser that supports location)
With the geo location you could now create a calculated column which calculates distance between you and your datapoints like stores, wells, clinics, etc
Spotfire 6.0 has a new function GreatCircleDistance() that makes this easy. E.g.:
DistanceInMiles = 3959 * GreatCircleDistance(${AppGeoLatitude},${AppGeoLongitude},[Latitude],[Longitude])
This is especially great for people in the field and are interested in analysing data around them geographically.
To get this feature in the regular browser we will do following series of steps
1) (${AppGeoLatitude} and ${AppGeoLongitude} are two reserved properties that can be used by Ipad app to set the location to. So for the purpose of this exercise we will use the same properties, so go ahead and define them in your analysis.
These are document properties and can be added from Edit>> Document Properties>> Properties(Tab) and then Add
2) Then create a text area and add some button that can trigger to get location.
<input id="getLocation" onclick="getmylocation()" >Get My Location</input>
3) Unfortunately at this point there is no way to set document properties using JS directly. So we do a little trick
4) We add two spotfire input field controls, mapping one of them to your AppGeoLatitude and other AppGeoLongitude
5) This will show up as two Spotfire controls (input fields)
6) Now if you don't really want to show the fields in the text area then wrap it around with a Div tag and use style visibility:hidden
So for e.g the html should show something like this
<input id="getLocation" onclick="getmylocation()" >Get My Location</input>
<div style="visibility:hidden">
<DIV id=mylatitude><SpotfireControl id="1a6f119726374d7f94c5b6951f5e6daa" /> </DIV>
<DIV id=mylongitude><SpotfireControl id="2d38a9e7d8b740b39b4e3554c5ba78b2" /> </DIV>
7) Now comes the javascript part
8) We will write that in the getmylocation() function The code is as follows.
function getmylocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML = "Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
$("#mylatitude input").first().val(position.coords.latitude);
$("#mylatitude input").first().blur();
$("#mylongitude input").first().val(position.coords.longitude);
$("#mylongitude input").first().blur();
}
The getmylocation function gets the latitude and longitude for you,
Then when we do $("#mylatitude input").first() it looks for the first input tag inside if mylatitude div.
(Internally spotfire input field control basically generates a input field. So i use that logic to set the value using .val()
Then to trigger the actually property update you call the blur function.
Now basically this should get you the location and if there is a calculated column that uses the properties to calculate distance they should be automatically recalculated generating a distance for you which you can now use to filter.
Cheers!!!
Comments
Post a Comment