-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.js
115 lines (102 loc) · 3.92 KB
/
javascript.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
var currentInfoWindow;
var map;
$(document).ready(function () {
var initialLocation;
var siberia = new google.maps.LatLng(60, 105);
var newyork = new google.maps.LatLng(40.773637, -73.970350);
var browserSupportFlag = new Boolean();
function initialize() {
//this function builds the map
//remove google points of interest markers
var myStyles =[
{
featureType: "poi",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
];
//set map types
mapOptions = {
zoom:16,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: myStyles,
disableDefaultUI: true
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
infoWidth = 350
if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
infoWidth = 500
}
// Try geolocation
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
}
// Browser doesn't support Geolocation
else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function handleNoGeolocation(errorFlag) {
if (errorFlag == true) {
alert("Geolocation didn't work on your browser. We are starting you in NYC");
initialLocation = newyork;
} else {
alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
initialLocation = siberia;
}
map.setCenter(initialLocation);
}
google.maps.event.addListener(map, 'idle', function(evt) {
writeMarker();
});
}
function writeMarker() {
c = map.getCenter();
if (c) {
var lat = c.lat();
var lng = c.lng();
var url = 'http://api.geonames.org/findNearbyWikipedia?lat='+lat+'&lng='+lng+'&maxRows=10&username=andyjt';
$.get(url, function (data) {
$(data).find("entry").each(function(){
var marker = new google.maps.Marker({
position: new google.maps.LatLng($(this).find("lat").text(), $(this).find("lng").text()),
});
marker.setIcon("assets/img/MapMarkerHQ.png");
var infowindow = new google.maps.InfoWindow({
maxWidth: infoWidth,
content:'<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h2 id="firstHeading" class="firstHeading">'+$(this).find("title").text()+'</h2>'+
'<div id="bodyContent">'+
'<p>'+
$(this).find("summary").text()+
'<a href="'+$(this).find("wikipediaUrl").text()+'" target="_blank">'+
"Wikipedia Entry"+
'</a>'+
'</p>'+
'</div>'+
'</div>'+
'</div>'
});
google.maps.event.addListener(marker, 'click', function() {
if (currentInfoWindow) currentInfoWindow.close();
infowindow.maxWidth=window.innerWidth*.80;
infowindow.open(map,marker);
currentInfoWindow = infowindow;
});
marker.setMap(map);
});
},"xml");
}
}
google.maps.event.addDomListener(window, 'load', initialize);
});