-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleMarker.js
108 lines (91 loc) · 3.49 KB
/
googleMarker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var customIcons = {
restaurant: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
bar: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
var dummy="hello";
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(23.6145, 72.3418),
zoom: 6,
mapTypeId: 'roadmap'
});
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
var infoWindow = new google.maps.InfoWindow;
<?php
require_once('functions.php');
connectdb();
$query = "SELECT * from cities where city_name = 'Mumbai' or city_name='Delhi'";
$result = mysql_query($query);
?>
<?php
while($row = mysql_fetch_array($result)){
//echo '<option value="' . $row["city_name"]. '"> ' . $row["city_name"].'</option>';
echo ' var name ="'. $row["city_name"].'"; var address = ""; var type = "";';
echo 'var point = new google.maps.LatLng(parseFloat("'.$row["latitude"].'"),parseFloat("'.$row["longitude"].'"));';
echo 'var html = "<b>" + name + "</b> " + address;';
?>
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
waypts =[];
waypts.push({
location:"Kathmandu, Central Region, Nepal",
stopover:true
});
waypts.push({
location:"Ahmedabad, Gujrat",
stopover:true
});
calcRoute("Mumbai", "Delhi", waypts);
<?php
}
?>
}
function calcRoute(start, end, waypts) {
var request = {
origin:start,
destination:end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}