Does Mapbox geocoding API support intersections outside US? - mapbox

According to the Mapbox geocoding API docs, it supports searching for intersections of two roads through the following API call:
https://api.mapbox.com/geocoding/v5/{endpoint}/{street_1}%20and%20{street_2}.json
The example listed in the docs (Market Street / Fremont Street, San Francisco) works:
$ curl "https://api.mapbox.com/geocoding/v5/mapbox.places/Market%20Street%20and%20Fremont%20Street.json?types=address&proximity=-122.39738575285674,37.7925147111369453&access_token=[TOKEN]"
{
"type": "FeatureCollection",
"query": [
"market",
"street",
"and",
"fremont",
"street"
],
"features": [
{
"id": "address.826558382307746",
"type": "Feature",
"place_type": [
"address"
],
"relevance": 1,
"properties": {
"accuracy": "intersection"
},
"text": "Fremont Street",
"place_name": "Market Street and Fremont Street, San Francisco, California, United States",
"center": [
-122.3982976,
37.791734
],
"geometry": {
"type": "Point",
"coordinates": [
-122.3982976,
37.791734
]
},
...
},
...
]
}
but when I search for somewhere outside the US (e.g. King Street / Collins Street, Melbourne), it never returns an intersection:
$ curl "https://api.mapbox.com/geocoding/v5/mapbox.places/William%20Street%20and%20Collins%20Street.json?access_token=[TOKEN]&country=au&types=address&proximity=144.95979,-37.81638"
{
"type": "FeatureCollection",
"query": [
"william",
"street",
"and",
"collins",
"street"
],
"features": [
{
"id": "address.6899530118768598",
"type": "Feature",
"place_type": [
"address"
],
"relevance": 0.716667,
"properties": {
"accuracy": "street"
},
"text": "Williams Street",
"place_name": "Williams Street, St Arnaud Victoria 3478, Australia",
"center": [
143.25317765,
-36.62076935
],
"geometry": {
"type": "Point",
"coordinates": [
143.25317765,
-36.62076935
]
},
...
},
...
]
}
As far as I can tell, the geocoding intersection search only works for US-based addresses. I've tried different combinations of the country, proximity and bbox parameters to no success.
US-based addresses work:
"Market Street and Fremont Street, San Francisco" (used in the docs example)
"Broadway and Columbus Avenue, New York"
Non US-based addresses don't work at all:
"Collins Street and William Street, Melbourne"
"Eagle Street and Queen Street, Brisbane"
"George Street and Grosvenor Street, Sydney"
"Oxford Street and Tottenham Court Road, London"
"Avenue Des Champs-Élysées and Place Charles de Gaulle, Paris"
How do I get Mapbox geocoding intersection search to work for non-US addresses?
If this is not possible, is it documented anywhere? Nothing in the docs indicates that this is not available world-wide, and I can't think of any reason why it wouldn't be.

You can use Mapbox's geocoding API playground to try various queries. Based on my testing, it seems clear that intersection queries always resolve to the US, or to something other than an intersection.
So:
How do I get Mapbox geocoding intersection search to work for non-US addresses?
I doubt it is possible.
If this is not possible, is it documented anywhere?
Not that I can see.
Nothing in the docs indicates that this is not available world-wide, and I can't think of any reason why it wouldn't be.
Geocoders are built from lots of different data sources in different regions, with lots of different rules.
It's hard to imagine why Mapbox would deliberately introduce this limitation, but easy to imagine how it could unintentionally come to be. You may wish to contact them directly.

Related

Mapbox: Find POIs with defined radius

The task I need is:
input: geolocation coordinates from gps, radius
ouput: list of pois (just names) to user can choose
just need analogue for google nearby search (since their cost is too high for a production)
questions:
1) what API is more preferable for this? examples are appreciated
2) do I need own data for pois or there is build in date in mapbox for these purposes?
The Mapbox Tilequery API lets you do exactly this. Here is a step-by-step tutorial explaining how to work with this API, and this API playground lets you experiment with the API. The data queried by the API is determined by the tileset passed as a parameter to your API request. As noted in the linked documentation, tutorial, and playground, you can either use existing Mapbox tilesets are create your own tileset with custom data, depending on your use case.
Note that, depending on the structure of the underlying data in the tileset you use, you might need to do a little extra work to convert a feature returned by the Tilequery API into a name of a POI. For example, consider the response body for below API request which makes use of the default mapbox.mapbox-streets-v8 tileset:
https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/-93.1204,44.9472.json?radius=25&limit=5&dedupe&access_token=YOUR_MAPBOX_ACCESS_TOKEN
One particular feature returned by the response body is:
{
"type": "Feature",
"id": 4,
"geometry": {
"type": "Point",
"coordinates": [
-93.12041537130386,
44.947199821761615
]
},
"properties": {
"extrude": "true",
"height": 3,
"min_height": 0,
"type": "house",
"underground": "false",
"tilequery": {
"distance": 1.2132887872688276,
"geometry": "polygon",
"layer": "building"
}
}
}
Although there is no POI name here, you could use the returned coordinates in conjunction with the Mapbox reverse geocoding API endpoint to retrieve names and other relevant POI properties for the POI located at said coordinate.
conversation with Mapbox support
Hi Artemii​,
It's Alex from Mapbox Support, happy to help!
You will want to use the Mapbox Tilequery API. The option you will want to utilize is radius​. Please be advised that queries will use tiles from the maximum zoom of the tileset, and will only include the intersecting tile plus eight surrounding tiles when searching for nearby features. That means that if your tileset has a maximum extent of z20, the maximum radius that you can search is only a few meters. Here is an API playground that you can test the API out with.
I hope this was helpful!
Hi Alex,
thanks for the quick reply, one more question:
request:
https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/55.9414,54.7295.json?radius=25&limit=50&dedupe&geometry=point&access_token=YOUR_MAPBOX_ACCESS_TOKEN
response:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 8,
"geometry": {
"type": "Point",
"coordinates": [
55.94845533370972,
54.72732387401962
]
},
"properties": {
"house_num": "32",
"tilequery": {
"distance": 8.949637333832088,
"geometry": "point",
"layer": "housenum_label"
}
}
},
{
"type": "Feature",
"id": 23629792230,
"geometry": {
"type": "Point",
"coordinates": [
55.948566645383835,
54.72761119224691
]
},
"properties": {
"class": "general",
"filterrank": 4,
"maki": "marker",
"name": "Башинформсвязь",
"name_script": "Cyrillic",
"sizerank": 16,
"type": "Telecommunication",
"tilequery": {
"distance": 23.898768437893523,
"geometry": "point",
"layer": "poi_label"
}
}
}
]
}
question: I understand that I can find info about places I got in the response using reverse geocoding API, but is there another approach to do this? Ideally, I would like to get poi's names from one tilquery request, because in case of using two API's (tilquery + geocoding) I will have to query 4-5 queries instead of only 1 (just worrying because it impacts on cost).
Hi Artemii​,
There is a parameter in the Tilequery API called layers that you can use to target a specific layer of your style.
https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/55.9414,54.7295.json?radius=25&limit=50&dedupe&geometry=point&layers=poi_label&access_token=
Which gets this response:
{ "type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 32316157590,
"geometry": {
"type": "Point",
"coordinates": [
55.94142526388168,
54.7295828683082
]
},
"properties": {
"category_en": "Supermarket",
"category_zh-Hans": "超市",
"class": "food_and_drink_stores",
"filterrank": 1,
"maki": "grocery",
"name": "Магнит",
"name_script": "Cyrillic",
"sizerank": 16,
"type": "Supermarket",
"tilequery": {
"distance": 9.367370433680872,
"geometry": "point",
"layer": "poi_label"
}
}
}
]
}
You can take this response object and return all the information from the POI. The "name" property is the name of the POI. Was there other properties that you were looking for from the reverse geocoding that are not being returned by the tilequery? It would be helpful for you to share a full example of a workflow using both tilequery and reverse geocoding, and to hear more about your exact use case, and how this tilequery/reverse geocoding operation fits into your larger application workflow.
Hi Alex,
request (without poi label since it doesn't find few bars I know. But if you add this label you only see one result) : https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/55.9485,54.7275.json?radius=14&limit=50&dedupe&access_token=YOUR_MAPBOX_ACCESS_TOKEN request
response:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 5,
"geometry": {
"type": "Point",
"coordinates": [
55.9485,
54.7275
]
},
"properties": {
"extrude": "true",
"height": 15,
"min_height": 0,
"type": "building",
"underground": "false",
"tilequery": {
"distance": 0,
"geometry": "polygon",
"layer": "building"
}
}
},
{
"type": "Feature",
"id": 1297495121,
"geometry": {
"type": "Point",
"coordinates": [
55.94833781213748,
54.727526546045794
]
},
"properties": {
"class": "path",
"iso_3166_1": "RU",
"iso_3166_2": "RU-BA",
"len": 4450,
"oneway": "false",
"structure": "none",
"surface": "paved",
"type": "footway",
"tilequery": {
"distance": 10.859473551200084,
"geometry": "linestring",
"layer": "road"
}
}
},
{
"type": "Feature",
"id": 23629792230,
"geometry": {
"type": "Point",
"coordinates": [
55.948566645383835,
54.72761119224691
]
},
"properties": {
"class": "general",
"filterrank": 4,
"maki": "marker",
"name": "Башинформсвязь",
"name_script": "Cyrillic",
"sizerank": 16,
"type": "Telecommunication",
"tilequery": {
"distance": 13.10152056398561,
"geometry": "point",
"layer": "poi_label"
}
}
},
{
"type": "Feature",
"id": 7,
"geometry": {
"type": "Point",
"coordinates": [
55.94869895433047,
54.7274698331467
]
},
"properties": {
"extrude": "true",
"height": 3,
"min_height": 0,
"type": "building",
"underground": "false",
"tilequery": {
"distance": 13.251093067012334,
"geometry": "polygon",
"layer": "building"
}
}
}
]
}
If we decode the first pair of coordinates(55.9485, 54.7275) using reverse geocoding (https://docs.mapbox.com/search-playground), we get Smoky People, ул. Ленина, 32, Уфа, Республика Башкирия 450077, Russia and if we decode all pairs, we will be able to find more cafes and bars (poi's).
Hey Artemii,
The reason for the varied results are the sources of the queries.
The Tilequery API searches for things that are on our Mapbox Streets v8 tileset (which our Mapbox Streets v11 style uses). The data in this tileset majorly comes from OpenStreetMap. If there are missing or outdated places on the map, this is the perfect opportunity to help us improve our map! If you do want to add or edit anything, head to openstreetmap.org, create an account, and make improvements directly. You'll have the option to go through an interactive tutorial to get you started. There are more details for advanced editing here as well: https://labs.mapbox.com/mapping. The Mapbox Streets tileset is updated regularly as features are edited or added to the map, which means that if you edit OpenStreetMap, you will eventually see your changes reflected on your Mapbox map.
The Geocoding API contains data sources from governments, open data projects, and private companies. In some cases, results from the Geocoding API may differ from Mapbox Streets or OpenStreetMap data. Check out this documentation on how geocoding works at Mapbox.
I think the best way to reduce the amount of API calls you make would be to pick one API, either reverse geocoding or Tilequery, and stick with it. With OpenStreetMaps, as tedious as it sounds, you do have the ability to add any POIs you know are missing, or cross reference other sources to add POIs to the map, which will make the place visible on the map as well as appear in your tilequery. With the Geocoding API, due to the nature of some sources and licensing, not all the places that you can search are visible on the map.

Algolia Places API: How to get the street of a place?

We are evaluation algolia places API and want to use it to find the address of sights. As an example, we want to find "Reichstagsgebäude, Berlin" which works and we get the correct response:
{
"query": "Reichstag, Berlin",
"suggestion": {
"name": "Reichstagsgebäude",
"administrative": "Berlin",
"city": "Berlin",
"country": "Deutschland",
"countryCode": "de",
"type": "address",
"latlng": {
"lat": 52.5186,
"lng": 13.3761
},
"postcode": "10557",
"highlight": {
"name": "Reichstagsgebäude",
"city": "<em>Berlin</em>",
"administrative": "<em>Berlin</em>",
"country": "Deutschland"
},
"value": "Reichstagsgebäude, Berlin, Berlin, Deutschland"
}
}
But how to get the real address of the Building with the Street name and Street Number included, which should be "Platz der Republik 1"
Currently, Algolia Places has street-level precision. We currently only have data for house-level precision (i.e., street name and street number) for France. This is an area we are actively looking to improve, but the data is still in process.

Can I retrieve house number on mapbox reverse geocoder?

Currently when I would like to retrieve address for coordinates I make following request as an example:
GET http://api.tiles.mapbox.com/v3/examples.map-zr0njcqy/geocode/-114.0701,51.0495.json
I get address information up to the street level but NO house number. Is there way to retrieve it as well? I think it's such an obvious need and cannot think of any problems extracting this date when you already extracted the rest.
{
"attribution": {
"mapbox-places": "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox © OpenStreetMap</a> <a class='mapbox-improve-map' href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a>"
},
"query": [
-114.0701,
51.0495
],
"results": [
[
{
"id": "street.31973701",
"lat": 51.0476559,
"lon": -114.0703042,
"name": "3 St SW",
"type": "street"
},
{
"bounds": [
-114.36183200000002,
50.84361600000001,
-113.87432100000002,
51.217528999999985
],
"id": "mapbox-places.10008775",
"lat": 51.03095,
"lon": -114.108491,
"name": "Calgary",
"type": "city"
},
{
"bounds": [
-120.00138351899996,
48.99667665000002,
-110.004763853,
60.00042158400004
],
"id": "province.2553712403",
"lat": 54.872006,
"lon": -115.003552,
"name": "Alberta",
"type": "province"
},
{
"bounds": [
-141.00275000000013,
40.043430830999895,
-47.69751888999983,
86.45371111000011
],
"id": "country.1833980151",
"lat": 76.304456,
"lon": -105.801333,
"name": "Canada",
"type": "country"
}
]
]
}
#rbrundritt is correct.
Most mapping applications (Google, Bing, etc) merely interpolate the location when given a street address. They are aware of the starting and ending address on a given block and then make an educated guess as to where the address you are search for is located on that block based on that. They don't actually store the outlines and the addresses of each property.

How can I prevent foreign objects appearing in a FB Places graph call?

I am confounded to find objects without any real link in my facebook graph calls. Say I make a call of places near a point in Denmark Europe. Along the list of results, I can risk to get items from singapore, korea, Austin TX and other completely off positions. But according to the FB result, the coordinates are matching.
Take this call for example :
FBGraph call, Center : 55.676127,12.581892 (Copenhagen, Denmark) , Distance : 1000m
Here are some expected results:
{
"name": "Fortunen Bar & Spiseri",
"location": {
"street": "Ved Stranden 18",
"city": "K\u00f8benhavn",
"country": "Denmark",
"zip": "1061",
"latitude": 55.677747326448,
"longitude": 12.5802503332
},
"category": "Local business",
"id": "454633487897742"
},
And suddently, a result that confuses me to the core :
{
"name": "CampusFrance Hong Kong",
"location": {
"street": "25/F, Tower II, Admirality Centre,18, Harcourt Road, Central, ",
"city": "Hong Kong",
"country": "Hong Kong",
"latitude": 55.67758,
"longitude": 12.58226
},
"category": "Government organization",
"id": "206130582769483"
},
I know i could filter them out with some name comparison on the Location country, but when people are close to borders, it would mess up my result, and also, if I request 20 items, i would risk ending up with 19 or 18, but still have a possible next page...
Anyone know of a flag or something one can set to avoid this ?
As Donn Lee mentions, this was a individual glitch. We are not sure why Facebook believes this entry is in Denmark, but its clear that it does not belong there.

iOS Find Location (Latitude,longitude) from Zipcode

What could be the best way to get location for a given zipcode. Would it work for countries outside US/Canada .Thanks
Use the Google geolocating API (try it out on google.com/maps):
Input for a Swiss ZIP code for example:
CH-9014
or a french one:
FR-34000
or german:
de-12101
or US:
us-90210
or canada:
ca-J5Z 1A1
or china:
cn-100000
for example:
yields
{
"status": "OK",
"results": [ {
"types": [ "postal_code" ],
"formatted_address": "9014 St Gallen, Switzerland",
"address_components": [ {
"long_name": "9014",
"short_name": "9014",
"types": [ "postal_code" ]
}, {
"long_name": "St Gallen",
"short_name": "St Gallen",
"types": [ "locality", "political" ]
}, {
"long_name": "Sankt Gallen",
"short_name": "SG",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "Switzerland",
"short_name": "CH",
"types": [ "country", "political" ]
} ],
"geometry": {
"location": {
"lat": 47.4082855,
"lng": 9.3323890
},
"location_type": "APPROXIMATE",
"viewport": {
"southwest": {
"lat": 47.3991076,
"lng": 9.3180504
},
"northeast": {
"lat": 47.4199564,
"lng": 9.3543340
}
},
"bounds": {
"southwest": {
"lat": 47.3991076,
"lng": 9.3180504
},
"northeast": {
"lat": 47.4199564,
"lng": 9.3543340
}
}
}
} ]
}
So the swiss ZIP code 9014 corresponds appx. to this location:
"lat": 47.4082855,
"lng": 9.3323890
See my answer on the geolocating API here:
How to get GLatLng object from address string in advance in google maps?
GeoNames offers a number of various zipcode geocoding services, including search for the location of a given zipcode. They support a number of various countries.
You would probably be most interested in the Placename Lookup for postalcode service
Google's API comes with some fairly nasty restrictions. Better to use open sources like GeoNames per #Claus Broch's suggestion.
I'm adding this answer to also note that MapQuest has recently put up an API to OpenStreetMap data. It doesn't do (as far as I can tell) zip code searching, but location names, directions, altitude etc are all freely queryable. I recently discovered it an I plan on replacing my calls to google maps API with it as soon as I can.
http://developer.mapquest.com/web/products/open