Skip to content

Commit 7467752

Browse files
authored
Merge pull request #1656 from tmh-dev/mapbox-place-name-for-address
Update mapbox result to use place_name as address
2 parents 8e0d650 + d3bcf62 commit 7467752

File tree

7 files changed

+284
-2
lines changed

7 files changed

+284
-2
lines changed

lib/geocoder/results/mapbox.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def neighborhood
5656
end
5757

5858
def address
59-
[place_name, street, city, state, postal_code, country].compact.join(', ')
59+
data['place_name']
6060
end
6161

6262
private

test/fixtures/mapbox_chicago_il

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"type": "FeatureCollection",
3+
"query": ["chicago"],
4+
"features": [
5+
{
6+
"id": "place.59328748",
7+
"type": "Feature",
8+
"place_type": ["place"],
9+
"relevance": 1,
10+
"properties": {
11+
"mapbox_id": "dXJuOm1ieHBsYzpBNGxJN0E",
12+
"wikidata": "Q1297"
13+
},
14+
"text": "Chicago",
15+
"place_name": "Chicago, Illinois, United States",
16+
"bbox": [-87.869226, 41.6326524, -87.4969592, 42.0348953],
17+
"center": [-87.63236, 41.881954],
18+
"geometry": {"type": "Point", "coordinates": [-87.63236, 41.881954]},
19+
"context": [
20+
{
21+
"id": "district.5162732",
22+
"mapbox_id": "dXJuOm1ieHBsYzpUc2Jz",
23+
"wikidata": "Q108418",
24+
"text": "Cook County"
25+
},
26+
{
27+
"id": "region.17644",
28+
"mapbox_id": "dXJuOm1ieHBsYzpST3c",
29+
"wikidata": "Q1204",
30+
"short_code": "US-IL",
31+
"text": "Illinois"
32+
},
33+
{
34+
"id": "country.8940",
35+
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
36+
"wikidata": "Q30",
37+
"short_code": "us",
38+
"text": "United States"
39+
}
40+
]
41+
}
42+
],
43+
"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."
44+
}

test/fixtures/mapbox_chicago_il_60647

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"type": "FeatureCollection",
3+
"query": ["60647"],
4+
"features": [
5+
{
6+
"id": "postcode.208334572",
7+
"type": "Feature",
8+
"place_type": ["postcode"],
9+
"relevance": 1,
10+
"properties": {"mapbox_id": "dXJuOm1ieHBsYzpER3J1N0E"},
11+
"text": "60647",
12+
"place_name": "Chicago, Illinois 60647, United States",
13+
"bbox": [-87.727075, 41.909191, -87.6752, 41.933705],
14+
"center": [-87.700436, 41.924799],
15+
"geometry": {"type": "Point", "coordinates": [-87.700436, 41.924799]},
16+
"context": [
17+
{
18+
"id": "place.59328748",
19+
"mapbox_id": "dXJuOm1ieHBsYzpBNGxJN0E",
20+
"wikidata": "Q1297",
21+
"text": "Chicago"
22+
},
23+
{
24+
"id": "district.5162732",
25+
"mapbox_id": "dXJuOm1ieHBsYzpUc2Jz",
26+
"wikidata": "Q108418",
27+
"text": "Cook County"
28+
},
29+
{
30+
"id": "region.17644",
31+
"mapbox_id": "dXJuOm1ieHBsYzpST3c",
32+
"wikidata": "Q1204",
33+
"short_code": "US-IL",
34+
"text": "Illinois"
35+
},
36+
{
37+
"id": "country.8940",
38+
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
39+
"wikidata": "Q30",
40+
"short_code": "us",
41+
"text": "United States"
42+
}
43+
]
44+
}
45+
],
46+
"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+
}

test/fixtures/mapbox_illinois

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"type": "FeatureCollection",
3+
"query": ["illinois"],
4+
"features": [
5+
{
6+
"id": "region.17644",
7+
"type": "Feature",
8+
"place_type": ["region"],
9+
"relevance": 1,
10+
"properties": {
11+
"mapbox_id": "dXJuOm1ieHBsYzpST3c",
12+
"wikidata": "Q1204",
13+
"short_code": "US-IL"
14+
},
15+
"text": "Illinois",
16+
"place_name": "Illinois, United States",
17+
"bbox": [-91.513079, 36.970298, -87.0117187, 42.5854443],
18+
"center": [-89.2749461071049, 40.1492928594374],
19+
"geometry": {
20+
"type": "Point",
21+
"coordinates": [-89.2749461071049, 40.1492928594374]
22+
},
23+
"context": [
24+
{
25+
"id": "country.8940",
26+
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
27+
"wikidata": "Q30",
28+
"short_code": "us",
29+
"text": "United States"
30+
}
31+
]
32+
}
33+
],
34+
"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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"type": "FeatureCollection",
3+
"query": ["logan", "square", "chicago"],
4+
"features": [
5+
{
6+
"id": "neighborhood.368872684",
7+
"type": "Feature",
8+
"place_type": ["neighborhood"],
9+
"relevance": 1,
10+
"properties": {
11+
"mapbox_id": "dXJuOm1ieHBsYzpGZnlNN0E",
12+
"wikidata": "Q3257855"
13+
},
14+
"text": "Logan Square",
15+
"place_name": "Logan Square, Chicago, Illinois, United States",
16+
"bbox": [-87.7314573, 41.9136391, -87.687314, 41.9321823],
17+
"center": [-87.70235, 41.92597],
18+
"geometry": {"type": "Point", "coordinates": [-87.70235, 41.92597]},
19+
"context": [
20+
{
21+
"id": "postcode.208334572",
22+
"mapbox_id": "dXJuOm1ieHBsYzpER3J1N0E",
23+
"text": "60647"
24+
},
25+
{
26+
"id": "place.59328748",
27+
"mapbox_id": "dXJuOm1ieHBsYzpBNGxJN0E",
28+
"wikidata": "Q1297",
29+
"text": "Chicago"
30+
},
31+
{
32+
"id": "district.5162732",
33+
"mapbox_id": "dXJuOm1ieHBsYzpUc2Jz",
34+
"wikidata": "Q108418",
35+
"text": "Cook County"
36+
},
37+
{
38+
"id": "region.17644",
39+
"mapbox_id": "dXJuOm1ieHBsYzpST3c",
40+
"wikidata": "Q1204",
41+
"short_code": "US-IL",
42+
"text": "Illinois"
43+
},
44+
{
45+
"id": "country.8940",
46+
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
47+
"wikidata": "Q30",
48+
"short_code": "us",
49+
"text": "United States"
50+
}
51+
]
52+
}
53+
],
54+
"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+
}

test/fixtures/mapbox_united_states

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"type": "FeatureCollection",
3+
"query": ["united", "states"],
4+
"features": [
5+
{
6+
"id": "country.8940",
7+
"type": "Feature",
8+
"place_type": ["country"],
9+
"relevance": 1,
10+
"properties": {
11+
"mapbox_id": "dXJuOm1ieHBsYzpJdXc",
12+
"wikidata": "Q30",
13+
"short_code": "us"
14+
},
15+
"text": "United States",
16+
"place_name": "United States",
17+
"bbox": [-179.9, 18.8164227, -66.8847656, 71.420291],
18+
"center": [-97.9222112121185, 39.3812661305678],
19+
"geometry": {
20+
"type": "Point",
21+
"coordinates": [-97.9222112121185, 39.3812661305678]
22+
}
23+
}
24+
],
25+
"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+
}

test/unit/lookups/mapbox_test.rb

+76-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_result_components
3333
assert_equal "United States", result.country
3434
assert_equal "US", result.country_code
3535
assert_equal "Garment District", result.neighborhood
36-
assert_equal "Madison Square Garden, 4 Penn Plz, New York, New York, 10119, United States", result.address
36+
assert_equal "Madison Square Garden, 4 Penn Plz, New York, New York 10119, United States", result.address
3737
end
3838

3939
def test_no_results
@@ -58,4 +58,79 @@ def test_mapbox_result_without_context
5858
assert_equal nil, result.city
5959
end
6060
end
61+
62+
def test_neighborhood_result
63+
result = Geocoder.search("Logan Square, Chicago, IL").first
64+
assert_equal [41.92597, -87.70235], result.coordinates
65+
assert_equal "Logan Square", result.place_name
66+
assert_equal nil, result.street
67+
assert_equal "Chicago", result.city
68+
assert_equal "Illinois", result.state
69+
assert_equal "60647", result.postal_code
70+
assert_equal "IL", result.state_code
71+
assert_equal "United States", result.country
72+
assert_equal "US", result.country_code
73+
assert_equal "Logan Square", result.neighborhood
74+
assert_equal "Logan Square, Chicago, Illinois, United States", result.address
75+
end
76+
77+
def test_postcode_result
78+
result = Geocoder.search("Chicago, IL 60647").first
79+
assert_equal [41.924799, -87.700436], result.coordinates
80+
assert_equal "60647", result.place_name
81+
assert_equal nil, result.street
82+
assert_equal "Chicago", result.city
83+
assert_equal "Illinois", result.state
84+
assert_equal "60647", result.postal_code
85+
assert_equal "IL", result.state_code
86+
assert_equal "United States", result.country
87+
assert_equal "US", result.country_code
88+
assert_equal nil, result.neighborhood
89+
assert_equal "Chicago, Illinois 60647, United States", result.address
90+
end
91+
92+
def test_place_result
93+
result = Geocoder.search("Chicago, IL").first
94+
assert_equal [41.881954, -87.63236], result.coordinates
95+
assert_equal "Chicago", result.place_name
96+
assert_equal nil, result.street
97+
assert_equal "Chicago", result.city
98+
assert_equal "Illinois", result.state
99+
assert_equal nil, result.postal_code
100+
assert_equal "IL", result.state_code
101+
assert_equal "United States", result.country
102+
assert_equal "US", result.country_code
103+
assert_equal nil, result.neighborhood
104+
assert_equal "Chicago, Illinois, United States", result.address
105+
end
106+
107+
def test_region_result
108+
result = Geocoder.search("Illinois").first
109+
assert_equal [40.1492928594374, -89.2749461071049], result.coordinates
110+
assert_equal "Illinois", result.place_name
111+
assert_equal nil, result.street
112+
assert_equal nil, result.city
113+
assert_equal "Illinois", result.state
114+
assert_equal nil, result.postal_code
115+
assert_equal "IL", result.state_code
116+
assert_equal "United States", result.country
117+
assert_equal "US", result.country_code
118+
assert_equal nil, result.neighborhood
119+
assert_equal "Illinois, United States", result.address
120+
end
121+
122+
def test_country_result
123+
result = Geocoder.search("United States").first
124+
assert_equal [39.3812661305678, -97.9222112121185], result.coordinates
125+
assert_equal "United States", result.place_name
126+
assert_equal nil, result.street
127+
assert_equal nil, result.city
128+
assert_equal nil, result.state
129+
assert_equal nil, result.postal_code
130+
assert_equal nil, result.state_code
131+
assert_equal "United States", result.country
132+
assert_equal "US", result.country_code
133+
assert_equal nil, result.neighborhood
134+
assert_equal "United States", result.address
135+
end
61136
end

0 commit comments

Comments
 (0)