Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function initialize() {
- var mapOptions = {
- center: new google.maps.LatLng(35.542284,-76.856),
- zoom: 11,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- var map = new google.maps.Map(document.getElementById("map_canvas"),
- mapOptions);
- $(document).ready(function(){
- $.getJSON('test.json', function(data) {
- for (i = 0; i < data.length; i++) {
- var item = data[i];
- var myLatlng = new google.maps.LatLng(item.lat, item.longs);
- var marker = new google.maps.Marker({
- position: myLatlng,
- map: map,
- title: item.name,
- icon: item.type + ".png"
- }); // end add new marker
- attachBox(marker, i)
- } //end for loop
- var ib = new InfoBox();
- function attachBox(marker, i) {
- google.maps.event.addListener(marker,'click',(function(marker, i) {
- var boxText = document.createElement("div");
- boxText.style.cssText = "border: 1px solid black;";
- boxText.innerHTML = item.name;
- var myOptions = {
- content: boxText,
- boxStyle: {
- opacity: 0.75,
- width: "280px"
- },
- closeBoxMargin: "12px 4px 2px 2px",
- };
- return function() {
- ib.setOptions(myOptions)
- ib.open(map, this);
- }
- })(marker, i));
- } // end attachBox
- }) // end getJSON
- }); // end jQuery
- } // end initialize
Add Comment
Please, Sign In to add comment