Google maps v3 API error

I use the Google Maps v3 API on one of my sites and everything works fine. However, quite unexpectedly since yesterday, every time I try to access the map page, I get 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 this happened?

+4
source share
4 answers

This is a problem with latitude and longitude.

Latitude and longitude should be "floating" numbers. If we pass other data types to it, this will close the browser because it is awaiting a response from Google with the wrong data type.

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);
}}
0
source

What does your code look like? Today I realized that I had the same problem (it worked the last couple of months) and came here for answers, but ultimately came across a solution.

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
    });
  }

:

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

, latidue longitude float initMap.

+2

, , . atlast . .

before my code was like

          script.src = "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=initialize";

changed it to

    script.src = "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=initMap&key=YOUR_API_KEY";

you can generate the api key from https://developers.google.com/maps/documentation/javascript/get-api-key and execute the initMap () code, as in https://developers.google.com/maps/

this fixed my problem.

0
source

Well, I found my problem: (The problem was that the browser page crashed with errors in the original question)

Source:

if($('#map_canvas').length) {

    //var lat = 53.8683;
    //var lng = 0.5;

    // instantiate geocoder
    geocoder = new google.maps.Geocoder();
    // create new latitude / longitude object
    var latlng = new google.maps.LatLng(lat,lng);

    // set map options
    var myOptions = {
        zoom: 5,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    // display map
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    // show the map div
    $('#map_canvas').show();
}

The following lines are compiled:

var lat = 53.8683;
var lng = 0.5;

Then it worked. The strange thing is that it worked perfectly for many years, when these vars have commented so far.

0
source

Source: https://habr.com/ru/post/1693777/


All Articles