Created
October 8, 2016 11:43
-
-
Save Megafry/d5d51bcde5db250253864e7134bae102 to your computer and use it in GitHub Desktop.
Google Map Markers Exemple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//original code from http://jsfiddle.net/07cwyj6n/ | |
//var icon = "https://cdn0.iconfinder.com/data/icons/social-networks-and-media-flat-icons/136/Social_Media_Socialmedia_network_share_socialnetwork_network-14-512.png"; | |
/* | |
var icon = { | |
url: "https://cdn0.iconfinder.com/data/icons/social-networks-and-media-flat-icons/136/Social_Media_Socialmedia_network_share_socialnetwork_network-14-512.png", // url | |
scaledSize: new google.maps.Size(30, 30), // scaled size | |
origin: new google.maps.Point(0,0), // origin | |
anchor: new google.maps.Point(15, 15) // anchor | |
}; | |
*/ | |
var icon = { | |
path: "M-10,0a10,10 0 1,0 20,0a10,10 0 1,0 -20,0", | |
fillColor: '#FF0000', | |
fillOpacity: .8, | |
anchor: new google.maps.Point(0,0), | |
strokeWeight: 0, | |
scale: 1, | |
//anchor: new google.maps.Point(0, 10) // anchor | |
} | |
//var json = "http://path/to/universities.json"; | |
var infowindow = new google.maps.InfoWindow(); | |
function initialize() { | |
var mapProp = { | |
center: new google.maps.LatLng(52.4550, -3.3833), //LLANDRINDOD WELLS | |
zoom: 7, | |
//scrollwheel: false, | |
//disableDefaultUI: true, | |
//mapTypeId: google.maps.MapTypeId.ROADMAP, | |
styles: googleMapStyle.StyleDark, | |
}; | |
map = new google.maps.Map(document.getElementById("googleMap"), mapProp); | |
// $.getJSON(json, function(json1) { | |
var json1 = { | |
"universities": [ | |
{ | |
"title": "Aberystwyth University", | |
"website": "http://www.aber.ac.uk", | |
"phone": "+44 (0)1970 623 111", | |
"lat": 52.415524, | |
"lng": -4.063066}, | |
{ | |
"title": "Bangor University", | |
"website": "http://www.bangor.ac.uk", | |
"phone": "+44 (0)1248 351 151", | |
"lat": 53.229520, | |
"lng": -4.129987}, | |
{ | |
"title": "Cardiff Metropolitan University", | |
"website": "http://www.cardiffmet.ac.uk", | |
"phone": "+44 (0)2920 416 138", | |
"lat": 51.482708, | |
"lng": -3.165881} | |
] | |
}; | |
$.each(json1.universities, function (key, data) { | |
var latLng = new google.maps.LatLng(data.lat, data.lng); | |
var marker = new google.maps.Marker({ | |
position: latLng, | |
map: map, | |
icon: icon, | |
animation: google.maps.Animation.DROP, | |
title: data.title, | |
}); | |
var details = "<h3>"+ data.title + "</h3> <a href=" + data.website + ">link</a>, " + data.phone + "."; | |
bindInfoWindow(marker, map, infowindow, details); | |
// }); | |
}); | |
} | |
function bindInfoWindow(marker, map, infowindow, strDescription) { | |
google.maps.event.addListener(marker, 'click', function () { | |
infowindow.setContent(strDescription); | |
infowindow.open(map, marker); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
//style for the map | |
var googleMapStyle = { | |
"StyleDark": [ | |
{ | |
"featureType": "all", | |
"elementType": "labels.text.fill", | |
"stylers": [ | |
{ | |
"saturation": 36 | |
}, | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 40 | |
} | |
] | |
}, | |
{ | |
"featureType": "all", | |
"elementType": "labels.text.stroke", | |
"stylers": [ | |
{ | |
"visibility": "on" | |
}, | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 16 | |
} | |
] | |
}, | |
{ | |
"featureType": "all", | |
"elementType": "labels.icon", | |
"stylers": [ | |
{ | |
"visibility": "off" | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative", | |
"elementType": "geometry.fill", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 20 | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative", | |
"elementType": "geometry.stroke", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 17 | |
}, | |
{ | |
"weight": 1.2 | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative", | |
"elementType": "labels", | |
"stylers": [ | |
{ | |
"visibility": "off" | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative.country", | |
"elementType": "all", | |
"stylers": [ | |
{ | |
"visibility": "simplified" | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative.country", | |
"elementType": "geometry", | |
"stylers": [ | |
{ | |
"visibility": "simplified" | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative.country", | |
"elementType": "labels.text", | |
"stylers": [ | |
{ | |
"visibility": "simplified" | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative.province", | |
"elementType": "all", | |
"stylers": [ | |
{ | |
"visibility": "off" | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative.locality", | |
"elementType": "all", | |
"stylers": [ | |
{ | |
"visibility": "simplified" | |
}, | |
{ | |
"saturation": "-100" | |
}, | |
{ | |
"lightness": "30" | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative.neighborhood", | |
"elementType": "all", | |
"stylers": [ | |
{ | |
"visibility": "off" | |
} | |
] | |
}, | |
{ | |
"featureType": "administrative.land_parcel", | |
"elementType": "all", | |
"stylers": [ | |
{ | |
"visibility": "off" | |
} | |
] | |
}, | |
{ | |
"featureType": "landscape", | |
"elementType": "all", | |
"stylers": [ | |
{ | |
"visibility": "simplified" | |
}, | |
{ | |
"gamma": "0.00" | |
}, | |
{ | |
"lightness": "74" | |
} | |
] | |
}, | |
{ | |
"featureType": "landscape", | |
"elementType": "geometry", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 20 | |
} | |
] | |
}, | |
{ | |
"featureType": "landscape.man_made", | |
"elementType": "all", | |
"stylers": [ | |
{ | |
"lightness": "3" | |
} | |
] | |
}, | |
{ | |
"featureType": "poi", | |
"elementType": "all", | |
"stylers": [ | |
{ | |
"visibility": "off" | |
} | |
] | |
}, | |
{ | |
"featureType": "poi", | |
"elementType": "geometry", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 21 | |
} | |
] | |
}, | |
{ | |
"featureType": "road", | |
"elementType": "geometry", | |
"stylers": [ | |
{ | |
"visibility": "simplified" | |
} | |
] | |
}, | |
{ | |
"featureType": "road.highway", | |
"elementType": "geometry.fill", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 17 | |
} | |
] | |
}, | |
{ | |
"featureType": "road.highway", | |
"elementType": "geometry.stroke", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 29 | |
}, | |
{ | |
"weight": 0.2 | |
} | |
] | |
}, | |
{ | |
"featureType": "road.arterial", | |
"elementType": "geometry", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 18 | |
} | |
] | |
}, | |
{ | |
"featureType": "road.local", | |
"elementType": "geometry", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 16 | |
} | |
] | |
}, | |
{ | |
"featureType": "transit", | |
"elementType": "geometry", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 19 | |
} | |
] | |
}, | |
{ | |
"featureType": "water", | |
"elementType": "geometry", | |
"stylers": [ | |
{ | |
"color": "#000000" | |
}, | |
{ | |
"lightness": 17 | |
} | |
] | |
} | |
] | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>GoogleMap</title> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
</head> | |
<base href=""> | |
<body class="dev"> | |
<div id="googleMap" style="height: 415px;"> | |
</div> | |
<!-- Scripts --> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,places&ext=.js"></script> | |
<script src="Resources/Public/JavaScript/main.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment