-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy path001.js
133 lines (110 loc) · 3.55 KB
/
001.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
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
// Some custom places to show when loading the full map, again to illustrate how it's done
var _places = [
// Random made up CUSTOM place
{
// Flag this place can edited (tooltip has an "Edit" button)
// Once editing has completed a callback is fired so you can save the details to your DB
autoShow: true,
lat: 53.79,
lng: -1.59,
name: "Somewhere",
street: "Over the rainbow, Up high way",
userData: 99
}
];
//
// Helper method for displaying the details of a place in this demo.
//
function getPlaceHtml(details) {
var html =
"UserData: " + details.userData + "<br/><br/>" +
"Location: " + details.lat + " / " + details.lng + "<br/><br/>" +
"Name: " + details.name + "<br/><br/>" +
"Address: " + details.street +
", " + details.town +
", " + details.area +
", " + details.postCode +
"<br/><br/>" +
"website: <a href='" + details.website + "'>website</a><br/>" +
"more <a href='" + details.url + "'>more page</a><br/>" +
"Tel: " + details.telNo
return html;
}
//
// Builds up the mapsed object for the demo, wires up default options and
// event handlers.
// There's quite a lot here as we're illustrating pretty much everything.
// Don't be put off ... you won't need anywhere near this level ... probably :oD
//
function showMap(e) {
$("#myMap").mapsed({
// Map initialisation options to pass onto Google Maps
mapOptions: {
zoom: 15,
center: new google.maps.LatLng(51.501364 , -0.14189)
},
// Adds a predictive search box
searchOptions: {
enabled: true,
//initSearch: "Football in Leeds",
placeholder: "Search for \"5aside\" ...",
geoSearch: "Businesses near {POSITION}"
},
// Turn geo button on
allowGeo: true,
findGeoOnLoad: true,
// Emulate places being loaded from a db
showOnLoad: _places,
getMarkerImage: function(m, markerType, title) {
if (title === "Here I am!") {
return {
url: "https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%8A%95|fff999|000000|",
size: new google.maps.Size(21, 34)
};
}
// not fussed about the others, just use the default
return null;
},
// Enables place selection
// ... note the presence of the callback is
// ... all that's required to enable selection
onSelect: function(m, details) {
var msg = getPlaceHtml(details);
m.showMsg("YOUR SELECTION CODE HERE", msg);
// indicate tip should be closed
return true;
},
});
}
$(document).ready(function() {
// show the map initially without geo location
// this way
// 1: We have a map on-screen whilst the user decides if they want to enable geo location
// Will look weird as you'd have a blank div until the user decides what to do
// 2: If the browser doesn't support geo, we still have a map
// 3: If the user decides they don't want to enable geo, they still have a fallback map to play with
showMap();
if (navigator.geolocation) {
// cool, geo is supported by the browser
navigator.geolocation.getCurrentPosition(
function (geoPos) {
// cool user has permitted geo tracking
// create a new "place" for where the user is
var geoPlace = {
autoShow: true,
name: "Here I am!",
lat: geoPos.coords.latitude,
lng: geoPos.coords.longitude
};
// add additional place to our places array we'll showOnLoad
_places.push(geoPlace);
// and show the map
showMap();
},
function (err) {
// user probably denied us geo access
alert("Sorry couldn't find you!");
}
);
}
});