Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mapbox result to use place_name as address #1656

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/geocoder/results/mapbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def neighborhood
end

def address
[place_name, street, city, state, postal_code, country].compact.join(', ')
data['place_name']
end

private
Expand Down
44 changes: 44 additions & 0 deletions test/fixtures/mapbox_chicago_il
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "FeatureCollection",
"query": ["chicago"],
"features": [
{
"id": "place.59328748",
"type": "Feature",
"place_type": ["place"],
"relevance": 1,
"properties": {
"mapbox_id": "dXJuOm1ieHBsYzpBNGxJN0E",
"wikidata": "Q1297"
},
"text": "Chicago",
"place_name": "Chicago, Illinois, United States",
"bbox": [-87.869226, 41.6326524, -87.4969592, 42.0348953],
"center": [-87.63236, 41.881954],
"geometry": {"type": "Point", "coordinates": [-87.63236, 41.881954]},
"context": [
{
"id": "district.5162732",
"mapbox_id": "dXJuOm1ieHBsYzpUc2Jz",
"wikidata": "Q108418",
"text": "Cook County"
},
{
"id": "region.17644",
"mapbox_id": "dXJuOm1ieHBsYzpST3c",
"wikidata": "Q1204",
"short_code": "US-IL",
"text": "Illinois"
},
{
"id": "country.8940",
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
"wikidata": "Q30",
"short_code": "us",
"text": "United States"
}
]
}
],
"attribution": "NOTICE: © 2024 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."
}
47 changes: 47 additions & 0 deletions test/fixtures/mapbox_chicago_il_60647
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"type": "FeatureCollection",
"query": ["60647"],
"features": [
{
"id": "postcode.208334572",
"type": "Feature",
"place_type": ["postcode"],
"relevance": 1,
"properties": {"mapbox_id": "dXJuOm1ieHBsYzpER3J1N0E"},
"text": "60647",
"place_name": "Chicago, Illinois 60647, United States",
"bbox": [-87.727075, 41.909191, -87.6752, 41.933705],
"center": [-87.700436, 41.924799],
"geometry": {"type": "Point", "coordinates": [-87.700436, 41.924799]},
"context": [
{
"id": "place.59328748",
"mapbox_id": "dXJuOm1ieHBsYzpBNGxJN0E",
"wikidata": "Q1297",
"text": "Chicago"
},
{
"id": "district.5162732",
"mapbox_id": "dXJuOm1ieHBsYzpUc2Jz",
"wikidata": "Q108418",
"text": "Cook County"
},
{
"id": "region.17644",
"mapbox_id": "dXJuOm1ieHBsYzpST3c",
"wikidata": "Q1204",
"short_code": "US-IL",
"text": "Illinois"
},
{
"id": "country.8940",
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
"wikidata": "Q30",
"short_code": "us",
"text": "United States"
}
]
}
],
"attribution": "NOTICE: © 2024 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."
}
35 changes: 35 additions & 0 deletions test/fixtures/mapbox_illinois
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"type": "FeatureCollection",
"query": ["illinois"],
"features": [
{
"id": "region.17644",
"type": "Feature",
"place_type": ["region"],
"relevance": 1,
"properties": {
"mapbox_id": "dXJuOm1ieHBsYzpST3c",
"wikidata": "Q1204",
"short_code": "US-IL"
},
"text": "Illinois",
"place_name": "Illinois, United States",
"bbox": [-91.513079, 36.970298, -87.0117187, 42.5854443],
"center": [-89.2749461071049, 40.1492928594374],
"geometry": {
"type": "Point",
"coordinates": [-89.2749461071049, 40.1492928594374]
},
"context": [
{
"id": "country.8940",
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
"wikidata": "Q30",
"short_code": "us",
"text": "United States"
}
]
}
],
"attribution": "NOTICE: © 2024 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."
}
55 changes: 55 additions & 0 deletions test/fixtures/mapbox_logan_square_chicago_il
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"type": "FeatureCollection",
"query": ["logan", "square", "chicago"],
"features": [
{
"id": "neighborhood.368872684",
"type": "Feature",
"place_type": ["neighborhood"],
"relevance": 1,
"properties": {
"mapbox_id": "dXJuOm1ieHBsYzpGZnlNN0E",
"wikidata": "Q3257855"
},
"text": "Logan Square",
"place_name": "Logan Square, Chicago, Illinois, United States",
"bbox": [-87.7314573, 41.9136391, -87.687314, 41.9321823],
"center": [-87.70235, 41.92597],
"geometry": {"type": "Point", "coordinates": [-87.70235, 41.92597]},
"context": [
{
"id": "postcode.208334572",
"mapbox_id": "dXJuOm1ieHBsYzpER3J1N0E",
"text": "60647"
},
{
"id": "place.59328748",
"mapbox_id": "dXJuOm1ieHBsYzpBNGxJN0E",
"wikidata": "Q1297",
"text": "Chicago"
},
{
"id": "district.5162732",
"mapbox_id": "dXJuOm1ieHBsYzpUc2Jz",
"wikidata": "Q108418",
"text": "Cook County"
},
{
"id": "region.17644",
"mapbox_id": "dXJuOm1ieHBsYzpST3c",
"wikidata": "Q1204",
"short_code": "US-IL",
"text": "Illinois"
},
{
"id": "country.8940",
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
"wikidata": "Q30",
"short_code": "us",
"text": "United States"
}
]
}
],
"attribution": "NOTICE: © 2024 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."
}
26 changes: 26 additions & 0 deletions test/fixtures/mapbox_united_states
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "FeatureCollection",
"query": ["united", "states"],
"features": [
{
"id": "country.8940",
"type": "Feature",
"place_type": ["country"],
"relevance": 1,
"properties": {
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
"wikidata": "Q30",
"short_code": "us"
},
"text": "United States",
"place_name": "United States",
"bbox": [-179.9, 18.8164227, -66.8847656, 71.420291],
"center": [-97.9222112121185, 39.3812661305678],
"geometry": {
"type": "Point",
"coordinates": [-97.9222112121185, 39.3812661305678]
}
}
],
"attribution": "NOTICE: © 2024 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."
}
77 changes: 76 additions & 1 deletion test/unit/lookups/mapbox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_result_components
assert_equal "United States", result.country
assert_equal "US", result.country_code
assert_equal "Garment District", result.neighborhood
assert_equal "Madison Square Garden, 4 Penn Plz, New York, New York, 10119, United States", result.address
assert_equal "Madison Square Garden, 4 Penn Plz, New York, New York 10119, United States", result.address
end

def test_no_results
Expand All @@ -58,4 +58,79 @@ def test_mapbox_result_without_context
assert_equal nil, result.city
end
end

def test_neighborhood_result
result = Geocoder.search("Logan Square, Chicago, IL").first
assert_equal [41.92597, -87.70235], result.coordinates
assert_equal "Logan Square", result.place_name
assert_equal nil, result.street
assert_equal "Chicago", result.city
assert_equal "Illinois", result.state
assert_equal "60647", result.postal_code
assert_equal "IL", result.state_code
assert_equal "United States", result.country
assert_equal "US", result.country_code
assert_equal "Logan Square", result.neighborhood
assert_equal "Logan Square, Chicago, Illinois, United States", result.address
end

def test_postcode_result
result = Geocoder.search("Chicago, IL 60647").first
assert_equal [41.924799, -87.700436], result.coordinates
assert_equal "60647", result.place_name
assert_equal nil, result.street
assert_equal "Chicago", result.city
assert_equal "Illinois", result.state
assert_equal "60647", result.postal_code
assert_equal "IL", result.state_code
assert_equal "United States", result.country
assert_equal "US", result.country_code
assert_equal nil, result.neighborhood
assert_equal "Chicago, Illinois 60647, United States", result.address
end

def test_place_result
result = Geocoder.search("Chicago, IL").first
assert_equal [41.881954, -87.63236], result.coordinates
assert_equal "Chicago", result.place_name
assert_equal nil, result.street
assert_equal "Chicago", result.city
assert_equal "Illinois", result.state
assert_equal nil, result.postal_code
assert_equal "IL", result.state_code
assert_equal "United States", result.country
assert_equal "US", result.country_code
assert_equal nil, result.neighborhood
assert_equal "Chicago, Illinois, United States", result.address
end

def test_region_result
result = Geocoder.search("Illinois").first
assert_equal [40.1492928594374, -89.2749461071049], result.coordinates
assert_equal "Illinois", result.place_name
assert_equal nil, result.street
assert_equal nil, result.city
assert_equal "Illinois", result.state
assert_equal nil, result.postal_code
assert_equal "IL", result.state_code
assert_equal "United States", result.country
assert_equal "US", result.country_code
assert_equal nil, result.neighborhood
assert_equal "Illinois, United States", result.address
end

def test_country_result
result = Geocoder.search("United States").first
assert_equal [39.3812661305678, -97.9222112121185], result.coordinates
assert_equal "United States", result.place_name
assert_equal nil, result.street
assert_equal nil, result.city
assert_equal nil, result.state
assert_equal nil, result.postal_code
assert_equal nil, result.state_code
assert_equal "United States", result.country
assert_equal "US", result.country_code
assert_equal nil, result.neighborhood
assert_equal "United States", result.address
end
end
Loading