-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLocation Based Markers.html
More file actions
118 lines (102 loc) · 3.72 KB
/
Location Based Markers.html
File metadata and controls
118 lines (102 loc) · 3.72 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Place searches</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
<script>
// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
var map;
var infowindow;
function initMap() {
// var pyrmont = {lat: 19.0730, lng: 72.8997};
map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(19.0730,72.8997),
zoom: 15
});
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: new google.maps.LatLng(19.0730,72.8997),
radius: 500,
type: ['hospital']
}, callback);
var infoWindow = new google.maps.InfoWindow({map: map});
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('You are here.');
map.setCenter(pos);
}, 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.');
}
// map = new google.maps.Map(document.getElementById('map_canvas'),
// map);
// GeoMarker = new GeolocationMarker();
// GeoMarker.setCircleOptions({fillColor: '#808080'});
// google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
// map.setCenter(this.getPosition());
// map.fitBounds(this.getBounds());
// });
// google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) {
// alert('There was an error obtaining your position. Message: ' + e.message);
// });
// GeoMarker.setMap(map);
// google.maps.event.addDomListener(window, 'load', initialize);
// }
// if(!navigator.geolocation) {
// alert('Your browser does not support geolocation');
// }
function callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
</script>
</head>
<body>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAYJY_vFKIl-VEdyoEd3hZI8Wv1JdNzTmI&libraries=places&callback=initMap" async defer></script>
</body>
</html>