MicroStrategy | Geo Location Filtering
You can filter data in a report to display information based on the distance between a location on the report, and the current location of an iPhone or iPad. For information on the requirements to support the Map widget on Android devices, refer to the MicroStrategy Readme. For example, in the image below, a report displays a list of stores.
When the report is viewed on a mobile device, the user can choose to display only stores within a ten mile radius.
If the report is displayed as a Map widget, only map markers for stores within a ten mile radius are displayed.
To filter data based on the distance from a point of interest to a mobile device, you must first create a metric to calculate this distance. Steps are below to create this metric.
Once you have created the distance calculation metric, you can use it to filter data by creating a prompt or filter using the metric. For example, you can:
- Create a prompt to allow users to display only data for locations within a specified radius of the mobile device
- Create a filter to automatically display data only for locations greater than 10 miles away from the mobile device
- In a Map widget, display map markers only for locations within a specified radius
- This procedure assumes that you have created an attribute with attribute forms containing the latitude and longitude of each location to use for the distance calculation. For example, the Store attribute in the example above has two attribute forms, Latitude and Longitude, which contain the latitude and longitude information for each store.
To create a metric to calculate the distance between locations and a mobile device
From any folder page, click the Create Prompt icon. The Create Prompt page is displayed.
Click Value Prompt. A list of options for creating a value prompt is displayed.
On the Definition tab, select the Numeric prompt option.
On the General tab, specify a title for the prompt in the Title field. The title is displayed along with the prompt when the prompt is run.
On the Style tab, from the Display style drop-down list, select Geo Location.
To specify whether the mobile device will automatically provide its latitude or longitude to answer the prompt, select the Latitude option under Location Coordinate. You will create a total of two Value prompts, one to specify latitude and one to specify longitude.
To save the prompt, select Save As. The Save As dialog box opens. Specify a name, description, and the location in which to save the prompt, then click OK. The prompt is saved.
Repeat the steps above, selecting the Longitude option under Location Coordinate to create a second Value prompt for the longitude. You must create a total of two prompts, one for the mobile device's longitude and one for the latitude.
To create the distance calculation metric, you must perform the following steps in MicroStrategy Desktop for several metrics, as listed in the table below. The table lists each metric to create, and the formula to use to create the metric, in the order in which you must create them. The final metric, Point_Distance, is the distance calculation metric.
In Desktop, from the File menu, point to New, and then Metric. The New Metric dialog box opens.
Click OK to create a new metric. The Metric Editor opens.
In the Definition pane, type the formula of the metric you want to create. Use the syntax in the table below for the metric's definition.
Click Save and Close. The Save As dialog box opens.
In the Object name field, type the name of the new metric. Use the name provided in the table below.
Navigate to the location in which you want to save the new metric, then click Save. The new metric is created.
Repeat the appropriate steps above to create each of the metrics required to calculate the distance to each store.
Once you have created the distance calculation metric, Point_Distance, you can create a prompt or filter that will use the metric. You can:
- Create a Metric Qualification prompt and add the prompt to a report, to let users specify a distance radius for which to display data. When the report is displayed on a mobile device, the user is presented with a prompt.
- Create a Metric Set Qualification filter. You can add the filter to a report or to a dataset report in a document, to automatically filter the data using the current location of the mobile device.
- Create a prompt or filter that will use the metric, then add it to a report displayed as a Map widget, or to the dataset report of a Map widget in a document. When the Map widget is displayed on a mobile device, only the map markers for locations within the specified distance from the mobile device are displayed. For general information and steps to define a Map widget, see Creating a Map widget for mobile devices.
The table below lists the metrics to create for the distance calculation metric, in the order they must be created.
Replace AttributeName with the name of the location attribute, and replace LatitudeFormName with the attribute form that contains the latitude information for each location. For example, for an attribute named Store with the attribute forms Latitude and Longitude, create a metric with the name Location_Lat, with the definition Max(Store@Latitude).
Replace AttributeName with the name of the location attribute, and replace LongitudeFormName with the attribute form that contains the longitude information for each location. For example, for an attribute named Store with the attribute forms Latitude and Longitude, create a metric with the name Location_Long, with the definition Max(Store@Longitude).
(Radians(([Location_Lat] - ?LatitudePromptName)) / 2)
Replace LatitudePromptName with the name of the Value prompt for latitude. For example, if the Value prompt is named Latitude, the definition is (Radians(([Location_Lat] - ?Latitude)) / 2).
(Radians (([Location_Long] - ?LongitudePromptName))/2)
Replace LongitudePromptName with the name of the Value prompt for longitude. For example, if the Value prompt is named Longitude, the definition is (Radians(([Location_Long] - ?Longitude)) / 2).
((Sin([DeltaLat/2]) * Sin([DeltaLat/2])) + (((Cos(Radians(?Latitude)) * Cos(Radians([Location_Lat]))) * Sin([DeltaLong/2])) * Sin([DeltaLong/2])))
(2 * [Atan2](Sqrt((1-A)), Sqrt(A)))
(3959 * C)
Note: This value is based on the radius of the Earth, 3,959 miles or 6,371 km. To calculate the distance between the stores and the mobile device using a different unit of distance, replace 3959 with the radius of the Earth in the units you want to use to measure distance. For example, to calculate distance in kilometers, the metric definition is (6371 * C).