Facebook Audience API - Targeting Audiences using Shapefiles - facebook

I know it's possible to target ads geographically based on zip codes and/or the radius around a given coordinate. Is it somehow possible to target ads geographically based on a shapefile (census Canada for example) or do we have to essentially "build" the shapefile using a combination of zip codes and radius inclusions / exclusions?

It seems the only real "shapes" for a target audience is either providing a country, state (or province if in Canada), congressional district and some zipcodes:
Canada province:
Audience Details:
Location - Living In:
Canada: Alberta
Age:
18 - 65+
US Congressional District
Audience Details:
Location - Living In:
United States: Pennsylvania's 1st District (US:PA01)
Age:
18 - 65+
US Zipcode
Audience Details:
Location - Living In:
United States: Beverly Hills (90210) California
Age:
18 - 65+
However, some zipcodes map to a simple point so you need to fallback to a coordinate and radius.
I guess the only way to create an audience for a given polygon is to try and fill its surface with circles, considering those circles have a minimum radius, so it will always be just an approximation.
There are examples of circle-packing around. I repaired an old gist (https://gist.github.com/shashashasha/1020117) to make you a plunkr example.
See this plunker
However, circle packing considers that circles shouldn't overlap each other, so you'll have to figure out another way to achieve the same.

Related

Overpass API : Loop through cities and find total length of road centerline per city

I am trying to prepare a Overpass QL such a way that it iterate through a list of City Names and find sum of lengths of all the road centerline features which are falling inside the city administrative boundary.
The idea is not to download to entire data rather to get only required total road length per city wise.
New York City, New York, USA
Toronto, Ontario, Canada
Jersey city, New Jersey, USA
<City_Name>, <STATE/PROVINCE>,
Above is the example input and below is sample QL with BBOX but need to automate either with overpy python api or writing single overpass QL for entire list of cities.
[out:json][timeout:25];(way"highway"="primary";way"highway"="secondary";way"highway"="tertiary";way"highway"="unclassified";way"highway"="residential";);(._;>;);out;
Appreciate if someone can give pointers to move ahead.
-Prem

Framework for plotting latitude longitude in a map based on country, state and district depending on the zoom level

I need a framework which takes a set of latitude longitude points and plots on a world map, grouped by country having the count of points as a marker on each country. Grouping here is the count of latitude longitude points in a country.
And as I drill down into a country, the clustering should change to state based one. And the next level, to districts.
Leaflet marker cluster is something very similar to what I have asked for, but the grouping is based on proximity and it doesn't consider country or state boundaries. That is, they are not region aware.
Regionbound.com has tweaked in some code in the leaflet code for making it region aware,
Sample marker definition:
var marker1 = new L.marker([-37.8, 145], {regions: ["Asia-Pac", "Australia", "VIC", "Melbourne"]} );
But the sample code says, every latitude longitude must be defined along with some extra parameter containing place information.
I could get the place information using reverse geocoding, but reverse geocoding every latitude longitude is time consuming right.
Highmaps provided by Highcharts is one another solution, but there, every country has code which should be assigned a value[count of point coordinates belonging to that country].
But all I have is latitude longitude points, no country or state information.
Thus, I need something which takes only a set of latitude longitude and does clustering based on country, state, district depending on the zoom level.
You have 2 separate needs in your questions:
Map your lat/lng coordinates to appropriate administrative areas. E.g. through the reverse geocoding that you mention.
Display "clusters" on those administrative areas depending on zoom level.
As for point 1, you know that lat/lng points do not say by themselves which administrative area(s) they belong to. So "reverse geocoding every latitude longitude" is a mandatory step. Whether time consuming or not depends on the solution you choose to perform this operation.
If I understand correctly, you would like a "framework" that could do that automatically for you. But frameworks are usually data agnostic, and if they do not have data about boundaries of those administrative areas, they cannot help you.
You may rather look for "services" (like the Mapbox Geocoding API that you mention) or software that would already have such data. It is not time consuming if you can program the lookup (or perform "bulk" operations) and if you are not limited by the requests rate and your amount of points to map (which may be the case with Mapbox).
You could very well set up your own application to perform this mapping:
As for the dataset for administrative areas boundaries, you would probably be interested in links in this post: Are there any free administrative boundaries available as shapefiles? If your points are limited to a few countries, it will be easier for you to find the appropriate data source(s).
Once you have that data, many GIS software should be capable of mapping your lat/lng points to the areas they belong to. This would be mainly for a "one-shot" operation, if your set of points do not change much.
A "web-compatible" alternative would be for example to use Leaflet with point in polygon for Leaflet plugin. You would need your boundaries data converted to GeoJSON format first. Again, GIS software should be capable of doing so, or many online services as well (search for "convert geojson" for example).
A server-side solution would avoid having to manage the entire boundaries data through network and in client browser (if you need to perform the mapping dynamically). I am sure many GIS servers are capable of performing this operation, once they are fed with the boundaries data.
For point 2, once you have completed the above step, I think you would have many options available, including those you mention (RegionBound, Highmaps).
Even with standard mapping libraries (Leaflet, OpenLayers 3), you would just need to build your "clusters" (markers on administrative areas with a number saying how many points are in there), like you have to do with Highmaps anyway for example.
Computing the number of "clustered" point is as easy as filtering your points per area name / code. Then switch the clusters to the desired administrative level when the map zoom changes.
So the key is really to determine first to which areas your points belong to (point 1).
Then a small question would rise about where to place the "cluster" marker:
On centroid of the administrative area? You need the coordinates of that centroid from your data source, or a good algorithm to compute it from the boundaries (good luck on that…).
On "center" of the bounding box of the area? Leaflet can easily compute that: from your area vector shape, you would do myShape.getBounds().getCenter().
On barycentre / centroid of the clustered points? This is what Leaflet.markercluster and RegionBound do (do not know for Highmaps).
Good luck!

Get coordinates for highway kilometers in Germany

Is there a way to get LON / LAT coordinates for German highway kilometers? I am looking for a search-string in the Mapbox API
i.e.: Autobahn A5, Kilometer 214 ==> bab+5+km+213+DE
https://api.mapbox.com/v4/geocode/mapbox.places/bab+5+km+213+DE.json?access_token=TOKEN
General bypass assuming the use case for having km mark on highway is if it's associated with some interchange on it: Let's assume we don't have such ready for use easy web API. So we need to build our "reverse geocoder" from km mark on highway to it's lat/lon.
We always have from popular GIS API's (Google maps etc.) coordinates for Interchanges, and of course we can order them.
Key point: In order to drive between 2 adjacent Interchanges, any decent routing web service algorithm (Google maps directions etc.) will always direct you to drive on that highway. It's logical... (with param like "shortest route" in case live heavy traffic and it will try to redirect you).
What I suggest is:
Let the first Interchange of the highway to be 0 K.
Ask for directions to the second interchange -
You will get the distance - so you know what is the km mark for the second interchange.
And so on to cover the highway until the km point you need.

MapKit: Check if a user is at an address. (In a Building)

Is there anyway, using MapKit, to check if a user is in a building, at a certain address?
I have the users current position (longitude, latitude):
I have a buildings address - for example, 298 Texas St, San Francisco.
Is there anyway I could tell if a user is at that address / in the building?
I have tried converting coordinates into an address, and just checking the address against the other one, however, my problem is that if the address is a house, and the user walks past it, it will return true, when, in reality, it is not.
Thanks for the help!
Addresses are usually reported as "geo-points", which is just a single lat/long coordinate. Without more information, you know nothing about the size or shape of the dwelling that represents the address.
Also, addresses are sometimes entered into mapping databases by interpolating between a starting address/coordinate and and ending address/coordinate. If the houses aren't evenly spaced, the coordinates of a given address can be wrong.
Plus, GPS's are pretty unreliable indoors, especially in office buildings and multi unit dwellings.
As a result, the short answer to your question is no.
You could ask the location manager for lat/long coordinates of the address, and then use another location manager call to get the distance from the user's current location, and use a distance value (20 meters?) to decide that the user is "at that address". That's likely the best you're going to be able to do.

Geo Fencing Identifier

How to specify the entire country as a region in region identifier.Wether it will accept the
identifier as :#"Uk"
here the code to reo identifier.How can i specify England or UK.Please help me to sort out
CLLocationCoordinate2D location2D = mapView.region.center;
CLRegion *regionForMonitoring = [[CLRegion alloc] initCircularRegionWithCenter:location2D radius:1 identifier:#"RegionIdentifier"];
[[Utils getLocationManager] startMonitoringForRegion:regionForMonitoring];
CLRegions are totally unsuitable for this purpose.
First of all, the radius specified is the distance in meters that the region covers - so in your case you are asking the system to monitor a region at a specific lat/long with a radius of 1 meter!
Also, system regions have a maximum number of regions that can be monitored (around 10 or so), and a maximum radius that can be used of around 400 meters after which the region will not work.
You really need to read the "Monitoring Shape Based Regions" section of this Apple document:
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html
There are two other possible approaches to what you are trying to do:
1) Use Significant Location Updates, and test on each update if you are in an area with a shape you specify.
2) Use CoreTelephony to look up the cell carrier your device is on and see if the carrier number matches one in the country of interest. Of course, this will not work on some iPads or other iOS devices with no cell connection.
Neither of those approaches will be exact around the edges, but will also not consume nearly as much battery life as using the GPS.