The Google Maps API is a very powerful tool that is relatively easy to use if you have some JavaScript background. The below screen was created with the code that follows (Google API Key obfuscated).
Basic Maps API example with hard-coded lat/long custom markers
Get an API key here: https://developers.google.com/maps/documentation/javascript/get-api-key
Maps API exposed operations reference: https://developers.google.com/maps/documentation/javascript/tutorial
<!DOCTYPE html>
<html>
<head>
<title>Custom Markers</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div>
Debug/Inspect...
</div>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(
document.getElementById('map'),
{center: new google.maps.LatLng(43.0589, -88.0988), zoom: 11, mapTypeId: 'hybrid'});
var icons = {
bucks: {
icon: 'bucks.png'
},
brewers: {
icon: 'brewers.png'
},
panthers: {
icon: 'panthers.jpg'
}
};
var features = [
{
position: new google.maps.LatLng(43.0280, -87.9712),
type: 'brewers'
}, {
position: new google.maps.LatLng(42.9930, -87.9210),
type: 'panthers'
}, {
position: new google.maps.LatLng(43.0000, -87.8379),
type: 'bucks'
}
];
// Create markers.
for (var i = 0; i < features.length; i++) {
var marker = new google.maps.Marker({
position: features[i].position,
icon: icons[features[i].type].icon,
map: map
});
};
//Must have API with access to the Places API to get marker click details without much manual code
}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXX&callback=initMap">
</script>
</body>
</html>
No comments:
Post a Comment