-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmnu-geocoder.html
142 lines (82 loc) · 2.69 KB
/
mnu-geocoder.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
<!doctype html>
<html lang = "en" >
<head>
<meta charset = "utf-8" >
<title></title>
<style>
body { font: 12pt monospace; margin: 0 10px 0 0; }
input { width: 100%; }
</style>
</head>
<body>
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyC08xQ2xRy3k5IHkEuuSWasdViOkk489Y0" ></script>
<p>Enter a location<br>
<input id = "inpAddress" placeholder="San Francisco CA" onchange = "geocoderAddress( geocoder );"
onclick="onclickInput();" title="Thank you Google Maps API!" >
<br>
<small>geocoder courtesy of Google</small>
</p>
<div id="menuGeocoderMessage" ></div>
<script>
// https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
let geocoder;
initGeocoder();
function initGeocoder() {
divMap = document.createElement( 'div' );
map = new google.maps.Map( divMap );
geocoder = new google.maps.Geocoder();
origin_autocomplete = new google.maps.places.Autocomplete( inpAddress );
origin_autocomplete.addListener(
'place_changed',
function() { setGeocoderMessage( origin_autocomplete.getPlace() ); }
);
if ( !parent.mainIframe ) {
parent.main.innerHTML = '<iframe id=mainIframe class=ifr src="analemma3-3d.html" ></iframe>';
}
}
function onclickInput() {
inpAddress.select();
parent.ifrGeocoder.height = '280';
}
function geocoderAddress( geocoder ) {
geocoder.geocode( {
'address': inpAddress.value },
function( results, status ) {
if ( status === google.maps.GeocoderStatus.OK ) {
} else {
parent.calculations.innerHTML = 'Geocode was not successful for the following reason: ' + status;
}
}
);
parent.ifrGeocoder.height = '120';
}
function setGeocoderMessage( place ) {
let txt;
let hash;
hash =
'^latitude^:^' + place.geometry.location.lat() + '^,' +
'^longitude^:^' + place.geometry.location.lng() + '^,' +
'^zoom^:^' + '16' + '^,' +
'^offsetUTC^:^' + place.utc_offset + '^';
if ( !place.geometry ) {
txt = 'Autocomplete\'s returned place contains no data';
} else {
txt =
'Latitude: ' + place.geometry.location.lat().toFixed( 4 ) + '<br>' +
'Longitude: ' + place.geometry.location.lng().toFixed( 4 ) + '<br>' +
'UTC Offset: ' + place.utc_offset + '<br>' +
'<p>Address:<br>' + place.adr_address + '</p>' +
( place.vicinity ? '<p>Vicinity:<br>' + place.vicinity + '</p>' : '' ) +
'<p>hash<br>' + hash + '</p>' +
'';
// parent.mainIframe.contentWindow.location.hash = hash;
parent.location.hash = 'analemma3-3d.html#' + hash;
parent.info.innerHTML = txt;
parent.place = place;
parent.offsetUTC = place.utc_offset
//console.log( 'place ', place );
}
}
</script>
</body>
</html>