2011-07-05 12 views
6

Estoy creando una página html estática para mostrar una cantidad de ubicaciones desde un dato. Yo sólo he copiado una de las muestras y estamos trabajando hacia atrás, pero estoy recibiendo el siguiente error en el Inspector de Safari:Google Maps API v3 - TypeError: El resultado de la expresión 'google.maps.LatLng' [undefined] no es un constructor

main.js:1SyntaxError: Parse error 
sample.htm:10TypeError: Result of expression 'google.maps.LatLng' [undefined] is not a constructor. 

Aquí está mi código html:

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Multi Markers Sample via Google Maps</title> 
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 
function initialize() { 
var myLatlng = new google.maps.LatLng(-30.2965590,153.1152650); 
var myLatlng1 = new google.maps.LatLng(-30.2956470,153.1123707); 
var myLatlng2 = new google.maps.LatLng(-30.2864430,153.1360230); 
var myOptions = { 
zoom: 13, 
center: myLatlng, 
mapTypeId: google.maps.MapTypeId.ROADMAP 
} 
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
var marker = new google.maps.Marker({ 
position: myLatlng, 
map: map, 
icon: 'http://www.google.com/intl/en_us/mapfiles/ms/icons/blue-dot.png', 
title:"Original Location"  }); 
var marker = new google.maps.Marker({ 
position: myLatlng1, 
map: map, 
title:"Tom Cruise"  }); 
var marker = new google.maps.Marker({ 
position: myLatlng2, 
map: map, 
title:"Lady Gaga"  }); 
} 
</script> 
</head> 
<body onLoad="initialize()"> 
<div id="map_canvas"></div> 
</body> 
</html> 

No estoy seguro lo que estoy haciendo mal aquí - realmente funciona en IE v8 en Windows pero no en Safari y necesito que funcione para ambos.

Respuesta

22

Agregue la función de devolución de llamada a su solicitud de google maps. Se ejecutará después de que Google cargue todo lo que necesita.

http://maps.google.com/maps/api/js?sensor=false&callback=initialize 
+2

+1 compañero de Ahorro de la vida; esta respuesta debe ser aceptada! – trojanfoe

+0

brillante ... +1 realmente :) – KAsh

+0

Lea doco o visite StackOverflow. ¡Gracias! – Greg0ry

1

hola por favor utilice este código usando jQuery `

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Multi Markers Sample via Google Maps</title> 
    <script src="js/jquery-1.10.2.min.js"></script> 

<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
     <style> 
     #map_canvas { 
      height: 500px; 
      width: 100%; 
     } 
    </style> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     var myLatlng = new google.maps.LatLng(-30.2965590, 153.1152650); 
     var myLatlng1 = new google.maps.LatLng(-30.2956470, 153.1123707); 
     var myLatlng2 = new google.maps.LatLng(-30.2864430, 153.1360230); 
     var myOptions = { 
      zoom: 13, 
      center: myLatlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     } 
     var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
     var marker = new google.maps.Marker({ 
      position: myLatlng, 
      map: map, 
      icon: 'http://www.google.com/intl/en_us/mapfiles/ms/icons/blue-dot.png', 
      title: "Original Location" 
     }); 
     var marker = new google.maps.Marker({ 
      position: myLatlng1, 
      map: map, 
      title: "Tom Cruise" 
     }); 
     var marker = new google.maps.Marker({ 
      position: myLatlng2, 
      map: map, 
      title: "Lady Gaga" 
     }); 
    }); 
</script> 
</head> 
<body > 
<div id="map_canvas"></div> 
</body> 
</html>` 
Cuestiones relacionadas