Created
October 26, 2018 21:11
-
-
Save ik5/fb1ab67fe721ca4e298b179b399aa4f8 to your computer and use it in GitHub Desktop.
Get OSM details on long and lat in go and javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch('https://nominatim.openstreetmap.org/reverse?format=json&lat=32.0959358&lon=34.8215234&addressdetails=1&accept-language=en') | |
.then((data) => { return data.json() } ) | |
.then((data) => { console.table(JSON.stringify(data)) } ) | |
.catch((err) => { console.error(err) } ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
const address = "https://nominatim.openstreetmap.org/reverse?format=json&lat=%f&lon=%f&addressdetails=1&accept-language=en" | |
func getDetails(lat, lon float64) string { | |
response, err := http.Get(fmt.Sprintf(address, lat, lon)) | |
if err != nil { | |
fmt.Println(err) | |
return "" | |
} | |
defer response.Body.Close() | |
contents, err := ioutil.ReadAll(response.Body) | |
if err != nil { | |
fmt.Println(err) | |
return "" | |
} | |
var result interface{} | |
err = json.Unmarshal(contents, &result) | |
if err != nil { | |
fmt.Println(err) | |
return "" | |
} | |
jsn := result.(map[string]interface{}) | |
return jsn["display_name"].(string) | |
} | |
func main() { | |
// 32.0959358, 34.8215234 | |
displayName := getDetails(32.0959358, 34.8215234) | |
fmt.Printf("%+v\n", displayName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on https://wiki.openstreetmap.org/wiki/Nominatim