Wie funktioniert die MapBox geocoder.reverseQuery?

stimmen
0

gibt es ein Beispiel, wie die MapBox Reverse-Abfrage zu verwenden. Ich fand ein Beispiel auf dem geocoder.query, aber ich kann nicht ein funktionierendes Beispiel für die Reverse-Abfrage zu finden scheinen.

Das folgende Beispiel wandelt eine Adresse lang lat, möchte ich lernen, wie man die umgekehrte Abfrage verwenden, um eine lat lange auf eine Adresse zu konvertieren. Die umgekehrte Abfrage dauert eine Eingabe [lon, lat], aber ich bin nicht sicher, wie das Ergebnis als eine Adresse zu erhalten und anzuzeigen.

https://www.mapbox.com/mapbox.js/api/v3.1.1/l-mapbox-geocoder/

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Use geocoder to set map position</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
L.mapbox.accessToken = '<your access token here>';
var geocoder = L.mapbox.geocoder('mapbox.places'),
    map = L.mapbox.map('map', 'examples.map-h67hf2ic');

geocoder.query('Chester, NJ', showMap);

function showMap(err, data) {
    // The geocoder can return an area, like a city, or a
    // point, like an address. Here we handle both cases,
    // by fitting the map bounds to an area or zooming to a point.
    if (data.lbounds) {
        map.fitBounds(data.lbounds);
    } else if (data.latlng) {
        map.setView([data.latlng[0], data.latlng[1]], 13);
    }
}
</script>
</body>
</html>
Veröffentlicht am 27/06/2018 um 19:07
quelle vom benutzer
In anderen Sprachen...                            


1 antworten

Wie funktioniert die MapBox geocoder.reverseQuery?

stimmen
0

gibt es ein Beispiel, wie die MapBox Reverse-Abfrage zu verwenden. Ich fand ein Beispiel auf dem geocoder.query, aber ich kann nicht ein funktionierendes Beispiel für die Reverse-Abfrage zu finden scheinen.

Das folgende Beispiel wandelt eine Adresse lang lat, möchte ich lernen, wie man die umgekehrte Abfrage verwenden, um eine lat lange auf eine Adresse zu konvertieren. Die umgekehrte Abfrage dauert eine Eingabe [lon, lat], aber ich bin nicht sicher, wie das Ergebnis als eine Adresse zu erhalten und anzuzeigen.

https://www.mapbox.com/mapbox.js/api/v3.1.1/l-mapbox-geocoder/

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Use geocoder to set map position</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
L.mapbox.accessToken = '<your access token here>';
var geocoder = L.mapbox.geocoder('mapbox.places'),
    map = L.mapbox.map('map', 'examples.map-h67hf2ic');

geocoder.query('Chester, NJ', showMap);

function showMap(err, data) {
    // The geocoder can return an area, like a city, or a
    // point, like an address. Here we handle both cases,
    // by fitting the map bounds to an area or zooming to a point.
    if (data.lbounds) {
        map.fitBounds(data.lbounds);
    } else if (data.latlng) {
        map.setView([data.latlng[0], data.latlng[1]], 13);
    }
}
</script>
</body>
</html>
Beantwortet am 27/06/2018 um 19:07
quelle vom benutzer

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more