forked from valeinterfac/cycling_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geolocation.js
49 lines (45 loc) · 1.55 KB
/
geolocation.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
function initMap()
{
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: {lat: 50.82253, lng: -0.13716}
});
var geocoder = new google.maps.Geocoder();
var geocoder2 = new google.maps.Geocoder();
document.getElementById('submit').addEventListener('click', function() {
geocodeAddress(geocoder, geocoder2, map);
});
}
function geocodeAddress(geocoder, geocoder2, resultsMap)
{
var address = document.getElementById('address').value;
geocoder.geocode({'address': address}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
resultsMap.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: resultsMap,
position: results[0].geometry.location
});
}
else {
alert('Geocode was not successful for the following reason: ' + status);
}
var latlong = document.getElementById('latlong');
//latlong.value = results[0].geometry.location.lat();
latlong.value = results[0].geometry.location;
});
var address2 = document.getElementById('address2').value;
geocoder2.geocode({'address': address2}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: resultsMap,
position: results[0].geometry.location
});
}
else {
alert('Geocode was not successful for the following reason: ' + status);
}
var latlong2 = document.getElementById('latlong2');
latlong2.value = results[0].geometry.location;
});
}