Skip to content

Locations

Introduction

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

Prerequisite

StreetHawkLocation component depends on StreetHawk's Analytics components. This document assumes that you have already integrated StreetHawkAnalytics component. if not then click here for detailed documentation on StreetHawkAnalytics components which describes steps to integrate Analytics component.

Integration steps

  • Include StreetHawk Locations Component

1.In Xamarin Studio, double click on Components folder
2.Click on "Get More Components", and search for StreetHawk Locations. Click Add to App
3.Once downloaded, click on Add to Project

  • Include Google Play Service - Location

Similar to StreetHawk's Locations component, Add Google Play Services - Location component.

  • Modify AndroidManifest.xml

Add location permissions as shown below

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

    <application>
    ...
    </application>
</manifest>

And add the following code under application tag

<manifest>
... 
    <application>       
        <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>
    <application>
<manifest>  
  • Include statements

Add the following include statements in you application's launcher class

using Com.Streethawk.Library.Locations;
using Com.Streethawk.Library.Core;
  • Initialise StreetHawk

Set application's app_key and call StreetHawk Init from OnCreate function of your application's launcher class as shown below

namespace XamHawkLocations
{
    [Activity (Label = "XamHawkLocations", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity
    {
        int count = 1;
        protected override void OnCreate (Bundle savedInstanceState)
        {
            Xamarin.Insights.Initialize (XamarinInsights.ApiKey, this);
            base.OnCreate (savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);
            StreetHawk.Instance.SetAppKey (<APPKEY>);
            StreetHawk.Instance.Init (Application);
        }
    }
}
  • Start Location Reporting

Start reporting locations by calling StartLocationReporting() as shown below

SHLocation.GetInstance(this).StartLocationReporting();