Is it possible to increase de accracy / precision of the Geocoder JSON response?
I could accomplish it using the Map, however, with the Geocoder It wasn't possible.
Problem Description
Using Mapbox Geocoder for JS:
<script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.7.2/mapbox-gl-geocoder.min.js"></script>
With the Tutorial Use the geocoder without a map:
https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder-no-map/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Use the geocoder without a map</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.6.1/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v2.6.1/mapbox-gl.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.7.2/mapbox-gl-geocoder.min.js"></script>
<link rel="stylesheet" href="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.7.2/mapbox-gl-geocoder.css" type="text/css">
<style>
#geocoder {
z-index: 1;
margin: 20px;
}
.mapboxgl-ctrl-geocoder {
min-width: 100%;
}
</style>
<div id="geocoder"></div>
<pre id="result"></pre>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiaGVldm8iLCJhIjoiY2t2bWZkZXVqNXkzcjJvcXB0MHZyeTV1ZiJ9.d-C9xDxy9sNFiiN4klZl_w';
const geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
types: 'country,region,place,postcode,locality,neighborhood'
});
geocoder.addTo('#geocoder');
// Get the geocoder results container.
const results = document.getElementById('result');
// Add geocoder result to container.
geocoder.on('result', (e) => {
results.innerText = JSON.stringify(e.result, null, 2);
});
// Clear results container when search is cleared.
geocoder.on('clear', () => {
results.innerText = '';
});
</script>
</body>
</html>
I receive a JSON response with lots of data, that I can configure with some options before sending the request. However, I couldn't find an option to increase the accuracy / precision of this response on the following documentation:
https://github.com/mapbox/mapbox-gl-geocoder/blob/main/API.md
The JSON Response has only 6 decimal digits, as can be seen on the Mapbox website example below and is not reliable to make calculations of close distances.
{
"type": "FeatureCollection",
"query": [
"825",
"s",
"milwaukee",
"ave",
"deerfield",
"il",
"60015"
],
"features": [{
"id": "address.4356035406756260",
"type": "Feature",
"place_type": [
"address"
],
"relevance": 1,
"properties": {},
"text": "Milwaukee Ave",
"place_name": "825 Milwaukee Ave, Deerfield, Illinois 60015, United States",
"matching_text": "South Milwaukee Avenue",
"matching_place_name": "825 South Milwaukee Avenue, Deerfield, Illinois 60015, United States",
"center": [
-87.921434,
42.166602
],
"geometry": {
"type": "Point",
"coordinates": [
-87.921434,
42.166602
],
"interpolated": true,
"omitted": true
},
"address": "825",
"context": [{
"id": "neighborhood.287187",
"text": "Lake Cook Road"
},
{
"id": "postcode.13903677306297990",
"text": "60015"
},
{
"id": "place.5958304312090910",
"wikidata": "Q287895",
"text": "Deerfield"
},
{
"id": "region.3290978600358810",
"short_code": "US-IL",
"wikidata": "Q1204",
"text": "Illinois"
},
{
"id": "country.9053006287256050",
"short_code": "us",
"wikidata": "Q30",
"text": "United States"
}
]
},
{
"id": "address.7464624790403620",
"type": "Feature",
"place_type": [
"address"
],
"relevance": 0.5,
"properties": {},
"text": "Milwaukee Ave",
"place_name": "825 Milwaukee Ave, Wheeling, Illinois 60090, United States",
"matching_text": "South Milwaukee Avenue",
"matching_place_name": "825 South Milwaukee Avenue, Wheeling, Illinois 60090, United States",
"center": [
-87.910299,
42.144504
],
"geometry": {
"type": "Point",
"coordinates": [
-87.910299,
42.144504
],
"interpolated": true
},
"address": "825",
"context": [{
"id": "neighborhood.287187",
"text": "Lake Cook Road"
},
{
"id": "postcode.9418633295906190",
"text": "60090"
},
{
"id": "place.9902190947082220",
"wikidata": "Q935043",
"text": "Wheeling"
},
{
"id": "region.3290978600358810",
"short_code": "US-IL",
"wikidata": "Q1204",
"text": "Illinois"
},
{
"id": "country.9053006287256050",
"short_code": "us",
"wikidata": "Q30",
"text": "United States"
}
]
},
{
"id": "address.6472754353404224",
"type": "Feature",
"place_type": [
"address"
],
"relevance": 0.5,
"properties": {},
"text": "Milwaukee Avenue",
"place_name": "825 Milwaukee Avenue, Glenview, Illinois 60025, United States",
"matching_text": "South Milwaukee Avenue",
"matching_place_name": "825 South Milwaukee Avenue, Glenview, Illinois 60025, United States",
"center": [
-87.852677,
42.071152
],
"geometry": {
"type": "Point",
"coordinates": [
-87.852677,
42.071152
]
},
"address": "825",
"context": [{
"id": "neighborhood.275266",
"text": "Northfield Woods"
},
{
"id": "postcode.3787740186211610",
"text": "60025"
},
{
"id": "place.10211845459386970",
"wikidata": null,
"text": "Glenview"
},
{
"id": "region.3290978600358810",
"short_code": "US-IL",
"wikidata": "Q1204",
"text": "Illinois"
},
{
"id": "country.9053006287256050",
"short_code": "us",
"wikidata": "Q30",
"text": "United States"
}
]
},
{
"id": "address.1225436500189372",
"type": "Feature",
"place_type": [
"address"
],
"relevance": 0.5,
"properties": {},
"text": "Milwaukee Ave",
"place_name": "825 Milwaukee Ave, Buffalo Grove, Illinois 60089, United States",
"matching_text": "South Milwaukee Avenue",
"matching_place_name": "825 South Milwaukee Avenue, Buffalo Grove, Illinois 60089, United States",
"center": [
-87.917484,
42.158084
],
"geometry": {
"type": "Point",
"coordinates": [
-87.917484,
42.158084
],
"interpolated": true
},
"address": "825",
"context": [{
"id": "neighborhood.287187",
"text": "Lake Cook Road"
},
{
"id": "postcode.11727721238210580",
"text": "60089"
},
{
"id": "place.8589721255665070",
"wikidata": "Q967086",
"text": "Buffalo Grove"
},
{
"id": "region.3290978600358810",
"short_code": "US-IL",
"wikidata": "Q1204",
"text": "Illinois"
},
{
"id": "country.9053006287256050",
"short_code": "us",
"wikidata": "Q30",
"text": "United States"
}
]
},
{
"id": "address.240107872738130",
"type": "Feature",
"place_type": [
"address"
],
"relevance": 0.5,
"properties": {},
"text": "Milwaukee Avenue",
"place_name": "825 Milwaukee Avenue, Wheeling, Illinois 60090, United States",
"matching_text": "South Milwaukee Avenue",
"matching_place_name": "825 South Milwaukee Avenue, Wheeling, Illinois 60090, United States",
"center": [
-87.898319,
42.126289
],
"geometry": {
"type": "Point",
"coordinates": [
-87.898319,
42.126289
],
"interpolated": true,
"omitted": true
},
"address": "825",
"context": [{
"id": "neighborhood.287189",
"text": "Milwaukee Avenue"
},
{
"id": "postcode.9418633295906190",
"text": "60090"
},
{
"id": "place.9902190947082220",
"wikidata": "Q935043",
"text": "Wheeling"
},
{
"id": "region.3290978600358810",
"short_code": "US-IL",
"wikidata": "Q1204",
"text": "Illinois"
},
{
"id": "country.9053006287256050",
"short_code": "us",
"wikidata": "Q30",
"text": "United States"
}
]
}
],
"attribution": "NOTICE: © 2018 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."
}