Filtering data based on geographical distance from an iPhone or iPad

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 example, in the image below, a report displays a list of stores.

Example of a list of store locations

When the report is viewed on an iPhone or iPad with MicroStrategy Mobile, the user can choose to display only stores within a ten mile radius.

List of store locations within a 5 mile radius

If the report is displayed as a Map widget, only map markers for stores within a ten mile radius are displayed.

Example of store locations in a 10 mile radius

To filter data based on the distance from a point of interest to an iPhone or iPad, 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:

Prerequisite

To create a metric to calculate the distance between locations and an iPhone or iPad

  1. From any folder page, click the Create Prompt Create Prompt icon icon. The Create Prompt page is displayed.

  2. Click Value Prompt. A list of options for creating a value prompt is displayed.

  3. On the Definition tab, select the Numeric prompt option.

  4. 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.

  5. On the Style tab, from the Display style drop-down list, select Geo Location.

  6. To specify whether the iPhone or iPad 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.

  7. 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.

  8. 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 iPhone or iPad's longitude and one for the latitude.

  9. 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.

  10. In Desktop, from the File menu, point to New, and then Metric. The New Metric dialog box opens.

  11. Click OK to create a new metric. The Metric Editor opens.

  12. 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.

  13. Click Save and Close. The Save As dialog box opens.

  14. In the Object name field, type the name of the new metric. Use the name provided in the table below.

  15. Navigate to the location in which you want to save the new metric, then click Save. The new metric is created.

  16. Repeat the appropriate steps above to create each of the metrics required to calculate the distance to each store.

  17. Once you have created the distance calculation metric, Point_Distance, you can create a prompt or filter that will use the metric. You can:

The table below lists the metrics to create for the distance calculation metric, in the order they must be created.

Metric Name

Metric Definition

Location_Lat

Max(AttributeName@LatitudeFormName)

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).

Location_Long

Max(AttributeName@LongitudeFormName)

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).

DeltaLat/2

(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).

DeltaLong/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).

A

((Sin([DeltaLat/2]) * Sin([DeltaLat/2])) + (((Cos(Radians(?Latitude)) * Cos(Radians([Location_Lat]))) * Sin([DeltaLong/2])) * Sin([DeltaLong/2])))

C

(2 * [Atan2](Sqrt((1-A)), Sqrt(A)))

Point_Distance

(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 iPhone or iPad 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).

Related topics