开发者

Google Map Not Appearing

开发者 https://www.devze.com 2023-01-29 10:27 出处:网络
Here\'s some html code I\'ve written: In the head I link cities.js, map.js and the google API <div id=\"top\">

Here's some html code I've written:

In the head I link cities.js, map.js and the google API

  <div id="top">
    <a href="index.php"><img alt="Harvard University" src="Images/logo.jpg"></a>
  </div>

  <div id="logo">
    Harvard Abroad: Mapped
  </div>

  <div id="button">
    <input onclick="mark();" type="button" value="Map">
  </div>

  <div id="map">
  </div>

Somehow, it doesn't load the map. The file that I've linked above, map.js does the loading and it seems like it isn't linked properly because I've included a document.write statement in it that doesn't print.

Here's the code for map.js (I link it in the file above), if it helps:

// default latitude
var LATITUDE = 42.3745615030193;

// default longitude
var LONGITUDE = -71.11803936751632;

// global reference to map
var map = null;

// load version 3 of the Google Maps API
google.load("maps", "3", {other_params: "sensor=false"});

/*
 * void
 * load()
 *
 * Loads map.
 */

function load()
{
    document.write("hi"); 
    // embed map
    var latlng = new google.maps.LatLng(LATITUDE, LONGITUDE);
    map = new google.maps.Map(document.getElementById("map"), {
     center: latlng,
     disableDefaultUI: true,
     mapTypeId: google.maps.MapTypeId.ROADMAP,
     navigationControl: true,
     scrollwheel: true,
     zoom: 17;
    });

    // prepare test icon for map
    testplacemarker = new google.maps.Marker({
     map: map,
     title: "Your home!"
    });
}

/*
 * void
 * mark()
 *
 * Markes locations of study abroad programs all around the world map
 */

function mark()
{
    document.write("hi");
    // mark program开发者_C百科s
    for (var city in CITIES)
    {
        // plant cities on map
        new google.maps.Marker({
         icon: "can't show hyperlink",
         map: map,
         position: new google.maps.LatLng(CITIES[city].latitude, CITIES[city].longitude),
         title: City
        });
    }
}

Also, just a heads up, cities.js is just an array like so:

var = CITIES {
  "Buenos Aires":
  {latitude: -34.6084, longitude: -58.3732},
  "Santiago":
  {latitude: -33.4254, longitude: -70.5665},

I have to get this page out in less than 1 hour. I would appreciate any help you can give me as I've been trying to get this done for some time now. I think there's some minor error that's stopping my javascript from running (the document.writes that I've inserted don't print which means map.js is never linked).


Firstly you have to create a map object

 var map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
0

精彩评论

暂无评论...
验证码 换一张
取 消