mardi 14 juin 2016

Google maps API v3 and Epoly.js issue - google is not defined error,

Hi I'm trying to use the following .js called epoly.js which is an extension that adds additional functions to the GPolygon and GPolyline classes,

Link to the .js site

I've followed the instruction on how to use the .js file but I'm constantly getting a same error,

epoly.js:62 Uncaught ReferenceError: google is not defined

I just have no clue where the problem comes from.. can anyone please help?

Index.php

<html>
<head>
    <script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.2.min.js"></script>
    <script src="js/googleMapFunctions.js"></script>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }
    </style>
</head>

<body onload = "initialize()">

    <form id="getData">
        <button name="control" type="submit" value="A">GET DATA</button>
    </form>

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

    <div id="tools">
    <button onclick="setRoutes();">Start</button></div>
    <div id="map_canvas" style="width:100%;height:100%;"></div>


    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=[MY API KEY]&callback=initMap">
    </script>
    <script src="js/epoly.js"></script>

</body>
</html>

[UPDATE] - Also tried with API v3 as well,

link to the epoly.js for google API v3.

Now I'm getting...

Uncaught ReferenceError: google is not defined

[UPDATE] - initialization files

for body onload = "initialize()" part

function initialize() {  

  infowindow = new google.maps.InfoWindow(
    { 
      size: new google.maps.Size(150,50)
    });

    var myOptions = {
      zoom: 12,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    address = 'Sydney'
    geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': address}, function(results, status) {
     map.fitBounds(results[0].geometry.viewport);

    }); 
  // setRoutes();
  } 

for script async defer ~~~ &callback=initMap" part

//Map Initialisation
function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
        zoom: 12,
        center: myLatLng
    });
}

Aucun commentaire:

Enregistrer un commentaire