Alex Reid
Alex Reid

Reputation: 202

ReferenceError: google is not defined, only (mozilla)

I trying to use google maps API with custom marks, on chrome work fine, but other browsers i have errors.

First error:

ReferenceError: google is not defined

Second error:

InvalidValueError: mapInitialize is not a function

JSfiddle example: example

on test site: testsite

What i do wrong? Please help!

Upvotes: 0

Views: 1284

Answers (3)

AhmadReza Payan
AhmadReza Payan

Reputation: 2281

Add this code at end of mapInitialize function :

var mapCenter = new google.maps.LatLng(56.946528, 24.118665);
map.setCenter(mapCenter);

Image result

Upvotes: 2

gotnull
gotnull

Reputation: 27224

You're not initialising your map correctly:

function loadScript(src, callback) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    if(callback)script.onload=callback;
    document.getElementsByTagName("head")[0].appendChild(script);
    script.src = src;
}

loadScript('http://maps.googleapis.com/maps/api/js?v=3&sensor=false&callback=initialize',
    function() {
        log('google-loader has been loaded, but not the maps-API ');
    });

function initialize() {
    log('maps-API has been loaded, ready to use');
    var mapOptions = {
          zoom: 8,
          center: new google.maps.LatLng(-34.397, 150.644),
          mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map_canvas'),
            mapOptions);
}

function log(str) {
    document.getElementsByTagName('pre')[0].appendChild(document.createTextNode('['+new Date().getTime()+']\n'+str+'\n\n'));
}
<pre><div id="map_canvas" style="height:200px"></div><pre>

Upvotes: 1

Philip Rollins
Philip Rollins

Reputation: 1291

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>

Guessing you don't have the JavaScript loaded.

Upvotes: -1

Related Questions