Friday, October 8, 2010

Mobile location targeting using latitude and longitude

With the rapid growth of mobile advertising, there is a need of knowing more accurately user’s location
Deciding on user location according to it’s ip is not accurate. Especially when user is using WAP, which assign the mobile device with an ip of some gateway.
More and more users allow applications to access their location. Publishers that has mobile device location can pass this information to mobile ad networks, in order to allow advertisers to target their campaigns more accurately.
The device location is defined by 2 parameters: longitude and latitude. These 2 parameters determine your location on the globe. Most modern smartphones can easily get this information. Applications can access this information if permission is granted by user.
So, after you convince your publishers to send you longitude and latitude of the user device (some will be able to send you this information and some won’t), you can start more accurately target your campaign’s geographical location.
How this can be technically done?
When creating a new campaign on your system, a new targeting should be added, allowing users to input this 3 values:
  • latitude
  • longitude
  • radius (in KM or whatever unit that works for you)
These 3 values allows the user to target the campaign for a specific point on the globe. Targeting a campaign for a specific point is not good enough, the radius parameter determines the area around the point for which we would like to target our campaign.
Of course, you can allow your users to define multiple values of latitude, longitude and radius, in order to target campaign simultaneously on several geographical locations.
In addition, you can also replace the input of latitude, longitude and a radius with a more visual way, like putting a map of the world and allowing user to visually drop points on the globe and define radiuses.
Let’s assume, that user inputs only a single set of: latitude, longitude and radius. What else do we need? The latitude and longitude of the user’s mobile device. We will get this information from the publisher. The information is send with the request for an ad as 2 parameters (latitude and longitude) or in whatever way you agreed with the publisher that this information is being passed.
To summarize, so far we have this information:
  • From campaign (defined when campaign is created):
    • Latitude
    • Longitude
    • Radius
  • From publisher (send on the ad request according to the latitude and longitude of user device):
    • Latitude
    • Longitude
What we have left to do?
Simply check if the location we got from the publisher falls in the location and radius defined for the campaign. If the location of the user device (received from publisher) is in the radius defined for campaign we should serve the campaign to the client, otherwise, we should search for another ad to show.
How do we check?
We calculate the distance between the 2 locations we have (the one defined for campaign and the one received from publisher) and see if this distance is smaller or equals to the radius we defined.
In order to calculate the distance between the 2 locations we will use the class Location which I have already write about on this post.
Let’s see how it looks in Java code. Suppose we have the following data
  • locationCampaign - Location of the campaign
  • locationUser – Location of user as it sent from publisher
  • radius - Radius in KM
For example:
Location locationCampaign = new Location(campaignLatitude, campaignLongitude)
Location locationUser = new Location(userLatitude, userLongitude)


the value in “isMatch” will contain “true” if the campaign should be delivered:
double distnace = locationCampaign.distnace(locationUser, KM);
boolean isMatch = ditance <= radius

No comments:

Post a Comment