-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
80 lines (72 loc) · 2.42 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 80%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?key="></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<!-- Load and patch test data. Remove this after providing your own data source. -->
<script src="mock_data.js"></script>
</head>
<body>
<div id="map"></div>
<pre>
Documentation:
1. Get an maps API key from: https://console.developers.google.com/flows/enableapi?apiid=maps_backend&keyType=CLIENT_SIDE&reusekey=true
2. Include the key in the script src 'maps/api/js?key=<client key>'.
3. Add your location API
3.1 Build location api returning points in [{"lat": "float", "lng": "float"}, ...] format.
3.2 Configure locationApi URL, remove mock ajax_response .
3.3 Extract location api key from session.
</pre>
<script>
var icon = {
path: google.maps.SymbolPath.CIRCLE,
fillOpacity: 0.5,
fillColor: '#C6203C',
strokeOpacity: 1.0,
strokeColor: '#C6203C',
strokeWeight: 3.0,
scale: 5
};
function loadData() {
var locationApi = 'http://example.com/api/Location',
apiToken; // TODO: get this from the request?
$.ajax({
url: locationApi,
data: {'token': apiToken}
}).done(initMap);
}
function initMap(data) {
var map;
var bounds = new google.maps.LatLngBounds();
map = new google.maps.Map(document.getElementById('map'));
data.forEach(function(v, i) {
var position = {lat: parseFloat(v.lat), lng: parseFloat(v.lng)};
var title = 'lat: ' + v.lat + ' ' + 'lng: ' + v.lng;
var marker = new google.maps.Marker({
position: position,
map: map,
title: title,
icon: icon
});
bounds.extend(marker.position);
});
// Fit map bounds to the plotted points
map.fitBounds(bounds);
}
loadData();
</script>
</body>
</html>