-
Notifications
You must be signed in to change notification settings - Fork 1
/
02.html
101 lines (78 loc) · 3.27 KB
/
02.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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/control.css">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</head>
<body>
<div id="map-canvas"></div>
<div id="control">
<input id="address" type="textbox" value="" placeholder="address"/>
<input id="encode-button" type="button" value="Encode"/>
<input id="latitude" type="textbox" value="" placeholder="latitude"/>
<input id="longitude" type="textbox" value="" placeholder="longitude"/>
</div>
<script type="text/javascript" src="js/assert.js"></script>
<script type="text/javascript">
var MYSTERY_LAT = 48.067;
var MYSTERY_LONG = 12.863;
var geocoder;
var map;
function initialize() {
// Initialize geocoder, a Geocoder object
// *** REPLACE null WITH YOUR CODE ***
geocoder = new google.maps.Geocoder();
// Initialize center, a LatLng object
// *** REPLACE null WITH YOUR CODE ***
var center = new google.maps.LatLng(MYSTERY_LAT, MYSTERY_LONG);
// Initialize mapOptions, a MapOptions object
// *** REPLACE null WITH YOUR CODE ***
var mapOptions = {
center: center,
zoom: 15
};
// Initialize map, a Map object
// *** REPLACE null WITH YOUR CODE ***
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
var loc = null;
// Initialize request, a GeocoderRequest object
// What are the two options for creating a GeocoderRequest?
// *** REPLACE null WITH YOUR CODE ***
var request = {'address': address};
// geocde your request
geocoder.geocode(request, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// Get location, a LatLng object, from results, an array of
// GeocoderResult objects, then set location to loc
// hint: use the first result
// second hint: location is a property of a property
// *** REPLACE null WITH YOUR CODE ***
loc = results[0].geometry.location;
// Display the latitude and longitude values of loc
// *** REPLACE null WITH YOUR CODE ***
document.getElementById("latitude").value = loc.lat();
document.getElementById("longitude").value = loc.lng();
// Center the map on loc
// *** YOUR CODE HERE ***
map.setCenter(loc);
// Add a marker at loc
// *** REPLACE null WITH YOUR CODE ***
var marker = new google.maps.Marker({
map: map,
position: loc
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
document.getElementById("encode-button").onclick = codeAddress;
</script>
</body>
</html>