cfgReadChar('system.oauth2_token'); // 18 Marina Gardens Dr, Singapore 018953 // 1.2845357,103.8626491 // 1.2805229,103.8638607 // 1.2805229,103.8660494 // data=!3m1!4b1!4m5!3m4!1s0x31da1902c39e5f79:0x940fef9215abd05b!8m2!3d1.2805229!4d103.8660494 // /data=!4m13!1m7!3m6!1s0x31da1902c39e5f79:0x940fef9215abd05b!2s18+Marina+Gardens+Dr,+Singapore!3b1!8m2!3d1.2805229!4d103.8660494!3m4!1s0x31da1902c39e5f79:0x940fef9215abd05b!8m2!3d1.2805229!4d103.8660494 $lat = 1.2805229; $lng = 103.8660494; $data = http_build_query( array( 'lat' => $lat, 'lng' => $lng ) ); $url = "http://oauth2.service/api/v1/reverse?" . $data; $opts = array( 'http' => array( 'method' => "GET", 'timeout' => 60, /* 1 minute */ 'header' => "Content-Type: application/x-www-form-urlencoded\r\n" . "Accept: application/json\r\n" . "Authorization: Server-Token ${httpAuthToken}\r\n", ), "ssl" => array( "verify_peer"=>false, "verify_peer_name"=>false, ) ); $context = stream_context_create($opts); $body = file_get_contents($url, false, $context); //syslog(LOG_WARNING,"BODY: ".$body); $geocoded = json_decode($body,true); if (is_array($geocoded) && is_array($geocoded["data"]) && !isset($geocoded["error"])) { //syslog(LOG_WARNING,json_encode($geocoded)); // Cache the result in DB /*Geocode::saveDistanceCache( $db->getConnect(), $fromLat, $fromLng, $toLat, $toLng, $geocoded["data"]); */ //return [$geocoded["data"], NULL]; } else if (is_array($geocoded) && isset($geocoded["error"])) { //$body = $geocoded["error"]; } var_dump($body);