-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
65 lines (58 loc) · 1.71 KB
/
map.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var map;
function initMap() {
// Create the map.
var pyrmont = {
lat: 23.8701334,
lng: 90.2713944
};
if (navigator.geolocation) {
try {
navigator.geolocation.getCurrentPosition(function(position) {
var pyrmont = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
});
} catch (err) {
}
}
map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 17
});
// Create the places service.
var service = new google.maps.places.PlacesService(map);
// Perform a nearby search.
service.nearbySearch({
location: pyrmont,
radius: 4000,
type: ['hospital']
},
function(results, status, pagination) {
if (status !== 'OK') return;
createMarkers(results);
getNextPage = pagination.hasNextPage && function() {
pagination.nextPage();
};
});
}
function createMarkers(places) {
var bounds = new google.maps.LatLngBounds();
for (var i = 0, place; place = places[i]; i++) {
var image = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};
var marker = new google.maps.Marker({
map: map,
icon: image,
title: place.name,
position: place.geometry.location
});
bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
}