Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Problem z Google Maps
trifek
post
Post #1





Grupa: Zarejestrowani
Postów: 340
Pomógł: 0
Dołączył: 28.09.2015

Ostrzeżenie: (0%)
-----


Witam serdecznie,
Mam taki kod:
  1.  
  2. <!DOCTYPE html>
  3. <html lang="pl">
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <meta name="description" content="">
  9.  
  10. <meta name="googlebot" content="index, follow" />
  11. <meta name="robots" content="index,follow" />
  12. <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate" />
  13. <meta http-equiv="Cache-Control" content="post-check=0, pre-check=0" />
  14. <meta http-equiv="Pragma" content="no-cache" />
  15.  
  16. <script src="js/jquery-2.1.1.min.js"></script>
  17.  
  18.  
  19. <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCTMtpxeKLL1goekXSe73nSY8mtgK9q2ys&v=3.exp&callback=initMap"></script>
  20. </head>
  21. </body>
  22. </html>
  23.  


I to mi zwraca:
InvalidValueError: initMap is not a function

Strona jest oczywiście większa, ale to już się sypie nawet w takim małym fragmencie (IMG:style_emoticons/default/sad.gif)
Co mam nie tak w powyższym kodzie?
Go to the top of the page
+Quote Post
mattii
post
Post #2





Grupa: Zarejestrowani
Postów: 133
Pomógł: 0
Dołączył: 29.01.2010

Ostrzeżenie: (0%)
-----


spróbuj:


  1. <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCTMtpxeKLL1goekXSe73nSY8mtgK9q2ys&v=3.exp&callback=initMap" async defer></script>

Go to the top of the page
+Quote Post
trifek
post
Post #3





Grupa: Zarejestrowani
Postów: 340
Pomógł: 0
Dołączył: 28.09.2015

Ostrzeżenie: (0%)
-----


nie pomogło (IMG:style_emoticons/default/sad.gif)

Może jak podam cały skrypt, to będzie łatwiej:
  1. <!DOCTYPE html>
  2. <html lang="pl">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="googlebot" content="index, follow" />
  6. <meta name="robots" content="index,follow" />
  7. <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate" />
  8. <meta http-equiv="Cache-Control" content="post-check=0, pre-check=0" />
  9. <meta http-equiv="Pragma" content="no-cache" />
  10. <script src="js/jquery-2.1.1.min.js"></script>
  11. <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCTMtpxeKLL1goekXSe73nSY8mtgK9q2ys&v=3.exp&callback=initMap"></script>
  12. <script src="jquery.geolocation.edit.js"></script>
  13. </head>
  14. <script type="text/javascript">
  15. $(document).ready(function() {
  16. $("#map").geolocate({
  17. lat: "#lat",
  18. lng: "#lng"
  19. });
  20.  
  21. });
  22. #map { width:100%; height:400px; }
  23.  
  24. <div id="map"></div>
  25. <input type="hidden" class="txtfield" id="lat" value="54.580570" name="szer">
  26. <input type="hidden" class="txtfield" id="lng" value="16.862211" name="dl">
  27.  
  28. </body>
  29. </html>


tutaj jest to online: http://serwer1356363.home.pl/teste.html

Ten post edytował trifek 22.09.2016, 22:11:39
Go to the top of the page
+Quote Post
markuz
post
Post #4





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

Ostrzeżenie: (0%)
-----


https://maps.googleapis.com/maps/api/js?key...p&callback=initMap

Cytat z dokumentacji:
Cytat
The async attribute lets the browser render the rest of your website while the Maps JavaScript API loads. When the API is ready, it will call the function specified using the callback parameter.


Czyli jak skrypty odpowiedzialne za API się wczytają to wywołują funkcję która nazywa się initMap - u Ciebie jej nie ma a powinna być. A więc możesz dodać:

Kod
var initMap = function() {
    // tutaj tworzysz mape
}
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 07:42