When calling the function initMap() , which loads the card, it gives an error

google is not defined.

function:

 function initMap(lat, lng, radius) { var myLatlng = new google.maps.LatLng(lat, lng); map = new google.maps.Map($("#map"), { center: myLatlng, zoom: 10, mapTypeId: google.maps.MapTypeId.ROADMAP }); var circle = new google.maps.Circle({ strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#FF0000', fillOpacity: 0.35, map: map, center: myLatlng, radius: radius, editable: true }); google.maps.event.addListener(circle, 'radius_changed', function() { $("#radius").attr("value", circle.getRadius() * 0.001); }); google.maps.event.addListener(circle, 'center_changed', function() { $("#google_lat").attr("value", parseFloat(circle.getCenter().lat())); $("#google_lng").attr("value", parseFloat(circle.getCenter().lng())); $("#lat_out").html(circle.getCenter().lat()); $("#lng_out").html(circle.getCenter().lng()); }); $("#radius").keyup(function(){ temp_radius = parseFloat(($(this).val()) * 1000); circle.setRadius(temp_radius); }); $("#radius").ready(function(){ $("#radius").val(5); }); $('#apply').click(function () { $("#wrap_for_map").attr('hidden', true); $("#google_lat").val(parseFloat(circle.getCenter().lat())); $("#google_lng").val(parseFloat(circle.getCenter().lng())); $("#google_radius").val(parseFloat(circle.radius)); }); $('#cancel').click(function cancel() { $("#wrap_for_map").attr('hidden', true); $("#google_lat").val(null); $("#google_lng").val(null); $("#radius").val(null); $("#google_radius").val(null) $('#lat_out').html(''); $('#lng_out').html(''); }); } 

Called the first time the page loads:

 $(document).ready(function () { var google_lat = $("#google_lat").val(); var google_lng = $("#google_lng").val(); initMap(google_lat, google_lng, temp_radius); 
  • Is the library connected? Are there any other errors in the console? - Grundy
  • Do you enable via <script src = " maps.googleapis.com/maps/api/js?sensor=false "></…>? - Dmitry Kalinin
  • still gives the error TypeError: Argument 1 of Window.getComputedStyle does not implement interface Element. - Jonny Manowar
  • connect via <script async defer type = "text / javascript" src = " maps.googleapis.com/maps/api/js?key=key&callback=initMap "> </ script> - Jonny Manowar
  • one
    Does this function accept a jQuery object? new google.maps.Map - Grundy

1 answer 1

Does this function accept a jQuery object? new google.maps.Map - Grundy 4 minutes ago

Yes, indeed, the error was due to this corrected to map = new google.maps.Map(document.getElementById("map"), and earned