Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps v3 API Error

Tags:

google-maps

I am using Google Maps v3 API on one of my websites and everything was working fine. However quite suddenly since yesterday every time i try to access the map page i 'm getting this error:

Error: Script terminated by timeout at: 
f@http://maps.googleapis.com/maps-api-v3/api/js/32/1a/map.js:1:175 
next@http://maps.googleapis.com/maps-api-v3/api/js/32/1a/map.js:2:310 
hx@http://maps.googleapis.com/maps-api-v3/api/js/32/1a/map.js:7:457
_.jl.prototype.Yb<@http://maps.googleapis.com/maps-api-v3/api/js/3/1a/map.js:54:163 
Uy@http://maps.googleapis.com/maps-api-v3/api/js/32/1a/map.js:38:313
Xy/<@http://maps.googleapis.com/maps-api-v3/api/js/32/1a/map.js:39:307 

Any idea why is this happened ?

like image 857
Designer Avatar asked Feb 17 '18 16:02

Designer


2 Answers

This is the issue with Latitude and Longitude.

Latitude and Longitude should be of 'float' numbers. If we pass other datatypes to it, it freezes the browser as it is waiting for google response with wrong datatype.

function drawMap( lat, lng ) { lat = parseFloat(lat); lng = parseFloat(lng); if ( ! isNaN( lat ) && ! isNaN( lng ) ) // Before sending it to google let check if they are valid values
{
    var mapOptions = {
        center: new google.maps.LatLng(44.5452, -78.5389),
        zoom: 5
    };
    map = new google.maps.Map(document.getElementById('vehicle_country_region_from_map'),   mapOptions);
}}
like image 55
Adiyya Tadikamalla Avatar answered Oct 03 '22 06:10

Adiyya Tadikamalla


How does your code look like? Today, I realized I had the same problem (it's been working for the last couple of months) and came here for answers, but ultimatly stumbled upon a solution myself.

Old code:

<script>
    function initMap(lat,lon) {
        var uluru = {lat: parseFloat(lat), lng: parseFloat(lon)};
        var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 4,
        center: uluru
    });
  }

Changed to:

<script>
    function initMap(lat,lon) {
        var uluru = {lat: lat, lng: lon};
        var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 4,
        center: uluru
    });
  }

Notice that after the change, I parse my latidue & longitude strings to floats before calling the initMap function.

like image 40
Rasmus Westerlundh Avatar answered Oct 03 '22 07:10

Rasmus Westerlundh