|
|
|
อยากให้ระบบแสดงออกมาว่า Latitude, Longitude เป็นของสถานที่ไหน สามารถทำได้ไหมค่ะ |
|
|
|
|
|
|
|
เจอแบบที่ต้องการแล้วค่ะ แต่ตอนนี้ไม่ทราบว่าต้องเขียนยังไง ลอง ctrl+u ดู code แล้ว แต่ก็ไม่เข้าใจเลยค่ะ
ขอคำแนะนำด้วยนะค่ะ
http://demos.codexworld.com/get-address-from-latitude-longitude-using-google-maps-api-php/
|
|
|
|
|
Date :
2016-10-19 15:54:17 |
By :
Baitong_ch |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วนะค่ะใช้เป็นแบบนี้ค่ะ
Code (PHP)
<?php
$latitude = '13.936523416667';
$longitude = '100.58507536111';
$geolocation = $latitude.','.$longitude;
$request = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$geolocation.'&sensor=false';
$file_contents = file_get_contents($request);
$json_decode = json_decode($file_contents);
if(isset($json_decode->results[0])) {
$response = array();
foreach($json_decode->results[0]->address_components as $addressComponet) {
if(in_array('political', $addressComponet->types)) {
$response[] = $addressComponet->long_name;
}
}
if(isset($response[0])){ $first = $response[0]; } else { $first = 'null'; }
if(isset($response[1])){ $second = $response[1]; } else { $second = 'null'; }
if(isset($response[2])){ $third = $response[2]; } else { $third = 'null'; }
if(isset($response[3])){ $fourth = $response[3]; } else { $fourth = 'null'; }
if(isset($response[4])){ $fifth = $response[4]; } else { $fifth = 'null'; }
if( $first != 'null' && $second != 'null' && $third != 'null' && $fourth != 'null' && $fifth != 'null' ) {
echo "<br/>Address:: ".$first;
echo "<br/>City:: ".$second;
echo "<br/>State:: ".$fourth;
echo "<br/>Country:: ".$fifth;
}
else if ( $first != 'null' && $second != 'null' && $third != 'null' && $fourth != 'null' && $fifth == 'null' ) {
echo "<br/>Address:: ".$first;
echo "<br/>City:: ".$second;
echo "<br/>State:: ".$third;
echo "<br/>Country:: ".$fourth;
}
else if ( $first != 'null' && $second != 'null' && $third != 'null' && $fourth == 'null' && $fifth == 'null' ) {
echo "<br/>City:: ".$first;
echo "<br/>State:: ".$second;
echo "<br/>Country:: ".$third;
}
else if ( $first != 'null' && $second != 'null' && $third == 'null' && $fourth == 'null' && $fifth == 'null' ) {
echo "<br/>State:: ".$first;
echo "<br/>Country:: ".$second;
}
else if ( $first != 'null' && $second == 'null' && $third == 'null' && $fourth == 'null' && $fifth == 'null' ) {
echo "<br/>Country:: ".$first;
}
}
?>
|
|
|
|
|
Date :
2016-10-19 16:51:41 |
By :
Baitong_ch |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|