Skip to main content

Spotfire Geo Capabilities Using your browser geo location


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

Popular posts from this blog

Using Accordions in Spotfire Text Areas

Spotfire 6.0 provides great tools for quickly building your dashboard, but here we will learn to spice up things with the help of new 6.0 text area. If you are not aware the new 6.0 Text area supports HTML, Javascript and CSS. This opens up possibilities for doing a lot more with the text area. Some of the basic stuff can be seen here http://spotfire.tibco.com/qrt/UBSAN/presentation.html?pcode=100044   One of the cool things you can do is build an accordion panel in the text area for better utilization of the valuable screen real estate and helping the overall experience.(Watch the 0:15 second video below to see how accordion works - Sorry for the jitter in the video. The screen recorder does not record fast enough) Here is the html behind the text area : Please note that Spotfire controls are automatically created when you add text area controls, like filters, drop down lists etc. <DIV id="myaccordion"> <H3>Analysis Details</...

Calendar Chart in Spotfire

I recently had a colleague asking me to show him the data in a calendar format.. Something like this I basically used a scatterplot for this.  You can check out the original DXP here  http://bit.ly/spotcalendar Some key settings to make it a calendar. Please note Order date is the date of interest here These expressions are out of the box expressions, no need to handcode them, but select them in the axis value  X Axis    <BinByDateTime([Order Date],"DayOfWeek",0)> Y Axis    Week([Order Date]) Trellis into panels   <BinByDateTime([Order Date],"Year.Quarter.Month",2)> Manual layout 4 X 3 Labels  UniqueConcatenate(DayOfMonth([Order Date])) Shape Tiled Markers Marker by   <UniqueConcatenate([Order Date])> Happy plotting your calendar!!!

Spotfire Auto Save for recovery

This is an extension I build to auto save local copies of currently open DXP every 15 minutes.. I have tested briefly and it seems to be doing its job, please please please try and test it if you can access a server and deploy.. Key Notes - This add-on will Auto Save Files while only in Spotfire Analyst Client. The save time is hard coded for every 15 minutes. Files are saved only if they are changed or user has done some actions like marking, filtering etc. The Files are saved in temporary location of the system, generally which will be like C:\Users\<username>\AppData\Local\Temp\Spotfire AutoSave If a Library file is opened it will be saved on your local machine under the temp path C:\Users\<username>\AppData\Local\Temp\Spotfire AutoSave\Library Content\ Library path will be replicated in this autosave location. e.g. C:\Users\<username> \Local\Temp\Spotfire AutoSave\LibraryContent\mylibraryfolder\mylibraryfilename_mmddyyyy_HH...