-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
108 lines (94 loc) · 3.25 KB
/
map.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
<!DOCTYPE html>
<html>
<head>
<title>Women Safety</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css" title="style">
<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>
var map;
var service;
var infowindow;
function initMap() {
var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);
infowindow = new google.maps.InfoWindow();
map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 15
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pyrmont = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infowindow.setPosition(pyrmont);
infowindow.setContent('Location found.');
infowindow.open(map);
map.setCenter(pyrmont);
var request = {
location: pyrmont,
radius: '500',
query: 'police station',
fields: ['name', 'formatted_address', 'international_phone_number', 'geometry']
};
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
}, function() {
handleLocationError(true, infowindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infowindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infowindow, pos) {
infowindow.setPosition(pos);
infowindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infowindow.open(map);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createMarker(results[i], infowindow);
}
}
}
function createMarker(place, infowindow) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
var request = {
reference: place.reference
};
service.getDetails(request, function(details, status) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(details.name + "<br />" + details.formatted_address + "<br />" + details.formatted_phone_number);
infowindow.open(map, this);
});
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBbl-QdcG2sHyqxz4Qu_ZE7pjmZNY1KP7I&libraries=places&callback=initMap" async defer></script>
</body>
</html>