우편 번호 또는 도시 이름으로 경로 맵과 거리를 표시하고 싶습니다. 우리가 입력 한 장소와지도에서 입력 한 것과 그곳에서 생성 한지도 사이의 총 거리 그 (것)들은 계산 될 것이고, 그것이 긴급한 것을 도와주세요. 미리 감사드립니다.Google지도에서 우편 번호로 경로를 그리는 방법
1
A
답변
1
당신은 세 단계
1)
이 map1.php
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example:Post City or Zip</title>
</head>
<body >
<form action="map2.php" method="post" >
Enter 1st zip code/city <input type="text" name="input1" id="input1"><br/>
Enter 2nd zip code/city <input type="text" name="input2" id="input2">
<input type="submit">
</form>
</body>
</html>
2 작성 후 도시 또는 우편 번호지도를 생성) map2.php을 만들고 맵을 생성에서이 작업을 수행 할 수 있습니다 지도 및 getLatLong을 생성
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Directions Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: chicago
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
function calcRoute() {
var start = '<?php echo $_POST['input1']; ?>';
var end = '<?php echo $_POST['input2']; ?>';
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
</script>
</head>
<body onLoad="initialize(),calcRoute()">
<?php
// calculate laglong by address and zip code
function getLatLong($address){
if (!is_string($address))die("All Addresses must be passed as a string");
$_url = sprintf('http://maps.google.com/maps?output=js&q=%s',rawurlencode($address));
$_result = false;
if($_result = file_get_contents($_url)) {
if(strpos($_result,'errortips') > 1 || strpos($_result,'Did you mean:') !== false) return false;
preg_match('!center:\s*{lat:\s*(-?\d+\.\d+),lng:\s*(-?\d+\.\d+)}!U', $_result, $_match);
$_coords['lat'] = $_match[1];
$_coords['long'] = $_match[2];
}
return $_coords;
}
$to = getLatLong($_POST['input1']);echo "<br/>";print_r($to);
$from = getLatLong($_POST['input2']);echo "<br/>";print_r($from);
echo distance($to['lat'], $to['long'], $from['lat'], $from['long'], "m") . " miles";
// // calculate distance by lat long
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
} else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}
}
?>
<div id="map_canvas" style="top:30px;"></div>
</body>
</html>
() 기능 laglong 및 거리 함수 찾기 도시 또는 우편 번호 사이의 거리를 찾으십시오
0
먼저 gmaps api를 사용하여 쉽게 찾을 수있는 우편 번호의 위치 정보를 찾아야합니다. 그런 다음 "distanceTo"메서드를 사용하여 점 사이의 거리를 찾습니다 (geopoint 및 우편 번호 생성 geopoint). distanceTo 메소드는 거리를 미터로 제공합니다.
관련 문제
- 1. 맞춤형 Google지도에서 우편 번호로 검색 추가
- 2. 우편 번호로 경도/위도?
- 3. 이동하면서 Google지도에서 경로를 그리는 방법은 무엇입니까?
- 4. 주소를 우편 번호로 변환
- 5. MYSQL 우편 번호로 검색
- 6. 우편 번호로 위도/경도를 입력하십시오.
- 7. Google지도에서 마커를 동적으로 그리는 방법
- 8. Google지도에서 우편 번호 받기
- 9. 안드로이드에서보기로 경로를 그리는 방법
- 10. MapView에서 경로를 그리는 방법
- 11. 우편 번호로 Wordpress 위치 검색
- 12. 캐나다 우편 번호로 GeocodeQuery 사용
- 13. Google지도에서 경로를 시각적으로 표시하는 방법
- 14. Google지도에서 마커를 동적으로로드하고 그 사이에 경로를 그리는 방법은 무엇입니까?
- 15. Google지도에서 경로를 표시 Android
- 16. Google지도에서 수동으로 경로를 그립니다.
- 17. Google지도에서 경로를 그립니다.
- 18. Google지도에서 이동 경로를 그립니다.
- 19. geodjango - 도시, 주 또는 우편 번호로 검색
- 20. 다운로드 양식 - 파일을 우편 번호로 조합하십시오.
- 21. WP7 Bing Maps에서 우편 번호로 이동
- 22. Google지도에서 가장 가까운 학교 찾기 (우편 번호
- 23. 안드로이드 및 Google지도에서 경로를 그릴
- 24. 이 WPF 경로를 C#으로 그리는 방법
- 25. 터치로 임의의 경로를 그리는 방법 UIView에서 이동
- 26. CloudMade에서 두 위치 간 경로를 그리는 방법
- 27. 안드로이드에서 두 geopoints 사이의 경로를 그리는 방법
- 28. 크럼 경로를 사용하여지도에서 경로를 그리는 방법은 무엇입니까?
- 29. Google지도로시 /도 또는 우편 번호 입력
- 30. 지도에서 경로를 그리는 방법은 무엇입니까?
이 귀중한 code.it의 작품에 감사드립니다 – user1514019