Skip to content

Location

Introduction

StreetHawk's Location is used for running location-based campaigns based on the location of your application's user. Also, the component can be used for calculating the Work and Home locations of your application's user.

Pre-requisites

The documents assume that you have downloaded and added the boiler-plate code described in the introduction document. You will require IStreetHawkLocation.cs, StreetHawkLocation.cs (iOS) and StreetHawkLocation.cs (Android) in particular for StreetHawkGrowth component.

StreetHawk Location component depends on StreetHawk Analytics components. This document assumes that you have already integrated StreetHawk Analytics. If not then click here for detailed documentation which describes steps to integrate Analytics component.

Integration steps

  • Add StreetHawkLocation Component

Add StreetHawk Growth component in both iOS and Droid project as shown below:

  1. In iOS project, right click on component folder
  2. Click on "Get More Components" and search for StreetHawk Growth. Click Add to App.
  3. Once downloaded, click on Add to Project.
  4. Repeat the above steps for adding the component in .Droid project of your application

  • iOS
    Modify Info.plist to enable location service.
    Add NSLocationAlwaysUsageDescription: request “Always” permission. (Option available in iOS 8). This is needed when you use location functions, including "streethawk/Locations" or "streethawk/Geofences" or "streethawk/Beacons".


- Android
Copy and paste the below code in AndroidManifest.xml located under properties folder of your application's .Droid project

<?xml version="1.0" encoding="utf-8"?>
<manifest>

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:label="@string/app_name">
        <service
            android:name="com.streethawk.library.locations.StreethawkLocationService"
            android:enabled="true"
            android:exported="true" />

        <receiver
            android:name="com.streethawk.library.locations.LocationReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.streethawk.intent.action.gcm.STREETHAWK_LOCATIONS" />
                <action android:name="android.location.PROVIDERS_CHANGED" />
            </intent-filter>
        </receiver>

        <activity android:name="com.streethawk.library.locations.AskLocPermission" />
    </application>
</manifest>

  • Start Location Reporting

Open App.Xaml.cs in your Xamarin.forms project and the following code in OnStart function as shown below.

...
    DependencyService.Get<IStreetHawkLocations>().StartLocationReporting();
...
  • Delay asking for Permission
    By default, StreetHawk SDK requests location permission when function “Init” is called in the “OnStart” function. In case you may wish to delay asking the user for location permission, you can add the code be as shown below.
using StreetHawkCrossplatform;

//optional to delay ask for permission
DependencyService.Get<IStreetHawkLocations>().SetIsDefaultLocationServiceEnabled(false);  //make streethawkinit not ask for location permission, delay for later time.

//do DependencyService.Get<IStreetHawkAnalytics>().Init(); and other things.

DependencyService.Get<IStreetHawkLocations>().SetIsLocationServiceEnabled(true);  //later when ready to register for location service, call this.