map.js
function loadMap() {
var location = new google.maps.LatLng(13, 100);
var mapType = google.maps.MapTypeId.ROADMAP;
var zoomLevel = 6;
var map = createMap(location, zoomLevel, mapType);
var marker = createMarker(map, location, "First Marker");//***
}
function createMap(location, zoomLevel, mapType){
var options = {
center: location,
zoom: zoomLevel,
mapTypeId: mapType
};
var map = new google.maps.Map(document.getElementById("myMap"), options);
return map;
}
//pre function
function createMarker(map, location, message){
var marker = new google.maps.Marker({
position : location,
map : map,
title : message
});
return marker;
}
map.html
<!-- marker map -->
<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=TRUE_OR_FALSE"></script>
<script type="text/javascript" src="js/map.js"></script>
</head>
<body onload="loadMap()">
<div id="myMap" style="width:100%; height:100%;"></div>
</body>
</html>
ไม่มีความคิดเห็น:
แสดงความคิดเห็น