forked from mariagund/HackNYFall2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaps.html
141 lines (126 loc) · 4.36 KB
/
maps.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
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.
var map, infoWindow;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 6
});
infoWindow = new google.maps.InfoWindow;
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
console.log(pos.lat)
//codeLatLng(pos.lat, pos.lng)
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
infoWindow.open(map);
//map.setCenter(pos);
//getCity(pos, map);
}, function() {
handleLocationError();
});
} else {
// Browser doesn't support Geolocation
handleLocationError();
}
}
/*function getCity(location, map) {
var center1 = new google.maps.LatLng(location.lat, location.lng);
console.log(location.lat);
console.log(location.lng);
console.log(center1);
var request = {
location: center1,
radius: '500',
query: 'beach'
};
console.log(request)
var map = new google.maps.Map(document.getElementById('map'), {
center: center1,
zoom: 10
});
console.log(map.center)
service = new google.maps.places.PlacesService(map);
service.textSearch(request, getSearchResult);
}
function getSearchResult(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
var place = results[0];
console.log(place)
}
}
/*function codeLatLng(lat, lng) {
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results)
if (results[1]) {
//formatted address
alert(results[0].formatted_address)
//find country name
for (var i=0; i<results[0].address_components.length; i++) {
for (var b=0;b<results[0].address_components[i].types.length;b++) {
//there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
//this is the object you are looking for
city= results[0].address_components[i];
break;
}
}
}
//city data
alert(city.short_name + " " + city.long_name)
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}*/
function handleLocationError() {
console.log("location error")
/*infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infoWindow.open(map);*/
}
</script>
<body>
<div id = "map"></div>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBe9j3O1ay2z2yOm7M5fGilL_Jti-cL_uY&callback=initMap">
</script>
</body>
</html>