-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
155 lines (132 loc) · 5.77 KB
/
index.html
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE HTML>
<html>
<head>
<!--Map set to 100%, not resizable by user-->
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<!--Sensor means using GPS locator to determine the user's location-->
<script type="text/javascript" src="../common/scripts/jquery/jquery.js">
</script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true">
//sensor=set_to_true_or_false
</script>
<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js">
</script>
<script type="text/javascript"
src="http://www.google.com/jsapi?key=ABQIAAAA-O3c-Om9OcvXMOJXreXHAxQGj0PqsCtxKvarsoS-iqLdqZSKfxS27kJqGZajBjvuzOBLizi931BUow">
</script>
<script type="text/javascript">
var geocoder;
var initialLocation;
var browserSupportFlag = new Boolean();
var map;
function detectBrowser() {
var useragent = navigator.userAgent;
var mapdiv = document.getElementById("map_canvas");
if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 )
{
mapdiv.style.width = '100%';
mapdiv.style.height = '100%';
}
else {
mapdiv.style.width = '600px';
mapdiv.style.height = '800px';
}
}
function initialize() {
//var latlng = new google.maps.LatLng(-34.397, 150.644);
//var latlng = new google.maps.LatLng(40.65,-73.95);
geocoder = new google.maps.Geocoder();
//New York
var latlng = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
//google.loader.ClientLocation.latitude,
//google.loader.ClientLocation.longitude);
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
//1.ROADMAP = normal, default 2D tiles
//2.SATELLITE = photographic tiles
//3.HYBRID = mix for features as roads, city names
//4.TERRAIN = physical relief (mountains, rivers, etc)
//If 2 & 3 , then map object can get setTile(45)
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//map.setTile(45);
}
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(
function(position) {
initialLocation =
new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
}
// Try Google Gears Geolocation
else if (google.gears) {
browserSupportFlag = true;
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(
function(position) {
initialLocation =
new google.maps.LatLng(position.latitude,
position.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeoLocation(browserSupportFlag);
});
}
// Browser doesn't support Geolocation
else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function geoCodeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( {'address': address}, function (results, status) {
//geometry->location->{x:Pa;y:Qa}
// X coordinate
//console.log(results[0].geometry.location.Pa);
// Y coordinate
//console.log(results[0].geometry.location.Qa);
if (status = google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
// Map Marker
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
//console.log(results[0]);
}
else {
alert("Geocode was not successful:" + status);
}
});
console.log(map.center.Pa);
console.log(map.center.Qa);
}
</script>
</head>
<body onload="initialize();">
<input style="position:absolute;z-index:1000;bottom:100px;left:400px;width:250px;"
type="text" value="Brighton Beach" name="address" id="address" />
<input style="position:absolute;z-index:1000;bottom:140px;left:400px;"
type="button" value="Geocode" onclick="geoCodeAddress();" />
<input style="position:absolute;z-index:1000;bottom:140px;left:480px;"
type="text" value="Milk" onclick="" />
<input style="position:absolute;z-index:1000;bottom:140px;left:600px;"
type="button" value="Go Milk!" onclick="" />
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>