load Google maps API after onload

Asked

Viewed 909 times

2

I have a system that currently works with the google maps api, but I realized that the site is waiting for this API to be loaded to finish loading the page.

on the home page(index.php) I have the tag like this:

<!DOCTYPE html>
<html>
...
.
.
.
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
.
.
.
</html>

I do not use google maps in index.php, only it is done this way, because after the page is loaded the user clicks on a button that does a load to the map so:

$("#conteudo").load('veiculoDescarga.php');

When that tag script Google is placed inside that web fileDescarga.php the not working api does not load the other dependencies on it.

// quando executo qualquer coisa da API tipo esse exemplo 
new google.maps.DirectionsRenderer();   
//Tenho essa mensagem de erro
TypeError: google.maps.DirectionsRenderer is not a constructor

//outro exemplo
google.maps.event.addDomListener(window, 'load', initialize);

//outro erro exemplo
TypeError: google.maps.event is undefined

Does anyone know if it is possible to make this API work after making $.load() or onload ?

Edit 01 To illustrate better I will leave the images below with the explanations:

In the image below the tag googleapis is wheel normally see that this single tag makes the call searching for the other dependency tags and insert them, this case is ok. inserir a descrição da imagem aqui

But I don’t want it to be loaded there at first, I want that tag to be loaded from googleapis when I call the event. load() from jQuery, but note that when I do this the tag is loaded but does not call the other dependencies inserir a descrição da imagem aqui

1 answer

1

Try it this way:

$("#conteudo").load('veiculoDescarga.php', carregarMapa);

function carregarMapa(){
   // aqui você coloca os scripts de carregamento do mapa.
}
  • Didn’t work, gave the same mistake

  • has an html page with javacript when the user clicks on a vehicle, it takes the coordinates of the vehicle with javacript/jQuery and opens a $("<div>"). dialog(), this dialog opens an html where is the script with the Goole API settings and map canvas

  • Dialog opens an html with the canvas tag and the necessary javascript (parameters) to open the map

  • This javascript needed to open the map is what you put inside Function loadMapa() { //here } ??

  • What are the other references that do not load when you load the api into the vehicle.php?

  • I edited the question to try to detail the problem better

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.