-
-
Save andri-sudarmawijaya/1fff755e650f156702de01891dde98e7 to your computer and use it in GitHub Desktop.
Cara mendapatkan koordinat / longitude latitude Desa wilayah indonesia dengan openstreetmap dengan php
This file contains 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
<?php | |
$wilayah = [ | |
// nama desa | |
'desa' => "Sukaluyu", | |
// nama kecamatan | |
'kecamatan' => "Tamansari", | |
// nama kabupaten | |
'kab_kota' => "Bogor", | |
// nama provinsi | |
'provinsi' => "Jawa Barat" | |
]; | |
; | |
$parseUrl = implode(',',$wilayah); | |
$url = "https://nominatim.openstreetmap.org/search/{$parseUrl}?format=json&addressdetails=1&limit=1"; | |
$getContent = http_request($url); | |
$encodeString = json_decode($getContent); | |
var_dump($encodeString); | |
function http_request($url){ | |
// persiapkan curl | |
$ch = curl_init(); | |
// set url | |
curl_setopt($ch, CURLOPT_URL, $url); | |
// set user agent | |
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
// return the transfer as a string | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
// $output contains the output string | |
$output = curl_exec($ch); | |
// tutup curl | |
curl_close($ch); | |
// mengembalikan hasil curl | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment