|
|
|
google maps api ขอคำแนะนำเกี่ยวกับการหา ระยะทางหน่อยคับ |
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<title>map google</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
<script>
var map;
var directions;
var lomap1 = new google.maps.LatLng(18.8123522516383,98.99149417877197);
var lomap2 = new google.maps.LatLng(18.809752372579957,98.95287036895752);
function initialize() {
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var lngSpan = lomap2.lng() - lomap1.lng();
var latSpan = lomap2.lat() - lomap1.lat();
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
for (var i = 0; i < 5; i++) {
var position = new google.maps.LatLng(
lomap1.lat() + latSpan * Math.random(),
lomap1.lng() + lngSpan * Math.random());
var myTrip=[position,pos];
var flightPath = new google.maps.Polyline({path:myTrip,strokeColor:"#0000FF",
strokeOpacity:0.8,
strokeWeight:2
});
flightPath.setMap(map);
var marker = new google.maps.Marker({
position: position,
map: map
});
marker.setTitle((i + 1).toString());
attachSecretMessage(marker, i);
}
var infowindow = new google.maps.InfoWindow({
map: map,
position: pos,
//animation:google.maps.Animation.BOUNCE
content: 'ฉันอยู่ตรงนี้.'
});
map.setCenter(pos);
}, function() {
handleNoGeolocation(true);
});
} else {
handleNoGeolocation(false);
}
}
function attachSecretMessage(marker, num) {
var message = ['This', 'is', 'the', 'secret', 'message'];
var infowindow = new google.maps.InfoWindow({
content: message[num]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(marker.get('map'), marker);
});
}
function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(60, 105),
content: content
};
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body onload="initWithMapStart()">
<div id="map-canvas" style="width:500px;height:380px;" ></div>
</body>
</html>
อยากหาระยะจากจุด pos ไปจุด position ขอคพแนะนำหน่อยคับ
Tag : PHP, jQuery
|
|
|
|
|
|
Date :
2013-08-07 11:21:45 |
By :
angleblack |
View :
2372 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|