-
Notifications
You must be signed in to change notification settings - Fork 0
/
geolocate.html
178 lines (164 loc) · 5.34 KB
/
geolocate.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script defer>
// src = https://stackoverflow.com/questions/24625013/use-google-maps-api-to-display-street-view-of-a-house-based-on-an-address
var panorama;
var addLatLng;
var showPanoData;
var panorama;
function load_map_and_street_view_from_address(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{
address: address,
},
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var gps = results[0].geometry.location;
create_map_and_streetview(gps.lat(), gps.lng(), "map_canvas", "pano");
}
}
);
}
function create_map_and_streetview(lat, lng, map_id, street_view_id) {
var goo = google.maps,
map = $("#" + map_id),
pano = document.getElementById("pano"),
addLatLng = new goo.LatLng(lat, lng),
myOptions = {
zoom: 14,
center: addLatLng,
mapTypeId: goo.MapTypeId.ROADMAP,
backgroundColor: "transparent",
streetViewControl: false,
keyboardShortcuts: false,
};
if (!map.data("gmap")) {
//store the instances per $.data
map.data("gmap", new goo.MVCObject());
map.data("gmap").set("panorama", new goo.StreetViewPanorama(pano));
map.data("gmap").set("service", new goo.StreetViewService());
map.data("gmap").set("map", new goo.Map(map[0], myOptions));
map.data("gmap").set(
"marker",
new goo.Marker({
map: map.data("gmap").get("map"),
animation: goo.Animation.DROP,
position: addLatLng,
})
);
} else {
map.data("gmap").get("map").setCenter(addLatLng);
map.data("gmap").get("marker").setPosition(addLatLng);
//always create a new panorama
//otherwise the panorama will be broken as soon as there is no picture available
map.data("gmap").set("panorama", new goo.StreetViewPanorama(pano));
}
map.data("gmap")
.get("service")
.getPanoramaByLocation(addLatLng, 50, function (panoData, status) {
if (status != google.maps.StreetViewStatus.OK) {
$("#pano").html("No StreetView Picture Available").attr("style", "text-align:center;font-weight:bold").show();
return;
}
var angle = computeAngle(addLatLng, panoData.location.latLng);
var panoOptions = {
position: addLatLng,
addressControl: false,
linksControl: false,
panControl: false,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
},
pov: {
heading: angle,
pitch: 10,
zoom: 1,
},
enableCloseButton: false,
visible: true,
};
map.data("gmap").get("panorama").setOptions(panoOptions);
var map = new google.maps.Map(document.getElementById(map_id), myOptions);
var marker = new google.maps.Marker({
map: map,
animation: google.maps.Animation.DROP,
position: addLatLng,
});
function showPanoData(panoData, status) {
if (status != google.maps.StreetViewStatus.OK) {
$("#pano")
.html("No StreetView Picture Available")
.attr("style", "text-align:center;font-weight:bold")
.show();
return;
}
var angle = computeAngle(addLatLng, panoData.location.latLng);
var panoOptions = {
position: addLatLng,
addressControl: false,
linksControl: false,
panControl: false,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
},
pov: {
heading: angle,
pitch: 10,
zoom: 1,
},
enableCloseButton: false,
visible: true,
};
panorama.setOptions(panoOptions);
}
function computeAngle(endLatLng, startLatLng) {
var DEGREE_PER_RADIAN = 57.2957795;
var RADIAN_PER_DEGREE = 0.017453;
var dlat = endLatLng.lat() - startLatLng.lat();
var dlng = endLatLng.lng() - startLatLng.lng();
var yaw = Math.atan2(dlng * Math.cos(endLatLng.lat() * RADIAN_PER_DEGREE), dlat) * DEGREE_PER_RADIAN;
return wrapAngle(yaw);
}
function wrapAngle(angle) {
if (angle >= 360) {
angle -= 360;
} else if (angle < 0) {
angle += 360;
}
return angle;
}
$(document).ready(function () {
load_map_and_street_view_from_address("150 Glen Road, Toronto");
$("#change_street").click(function () {
alert("How do I pass the new address to the street view code?");
});
});
});
}
jQuery;
</script>
<title>Geolocate</title>
</head>
<body>
<h3>Enter an Address to view the street view</h3>
<form action="/" method="POST">
<textarea name="new_address" class="address">150 Glen Road, Toronto</textarea>
<input type="submit" id="change_street" value="Change Street View Address" />
</form>
<div class="map_container">
<div id="map_canvas_cont">
<div id="map_canvas"></div>
</div>
<div id="pano_cont">
<div id="pano"></div>
</div>
<button id="change_street" onclick={load_map_and_street_view_from_address($('textarea[name="new_address"]').val());
}>Change Street View Address</button>
</div>
</body>
</html>