Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript][PHP]Google Maps
krzesik
post
Post #1





Grupa: Zarejestrowani
Postów: 516
Pomógł: 1
Dołączył: 25.08.2012

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


Na początku Wesołych Świąt! :-)

mam kłopot z mapą. ładnie się wyświetla pobiera dane z bazy, ale.....
aby pojawił się punkt (lat i lon poprawnie pobrany z bazy) muszę kliknąć na mapę, co mam skopane?

  1.  
  2. var map;
  3. var marker = false;
  4.  
  5. function initMap() {
  6. var myLatLng = {lat: <? echo $z[lat]; ?>, lng: <? echo $z[lon]; ?>};
  7.  
  8.  
  9. var centerOfMap = new google.maps.LatLng(50.915, 18.818);
  10.  
  11. var options = {
  12. center: myLatLng,
  13. zoom: 11
  14. };
  15.  
  16. map = new google.maps.Map(document.getElementById('map'), options);
  17.  
  18. google.maps.event.addListener(map, 'click', function(event) {
  19.  
  20. var clickedLocation = event.latLng;
  21.  
  22. if(marker === false){
  23. marker = new google.maps.Marker({
  24. position: myLatLng,
  25. map: map,
  26. draggable: true
  27. });
  28. google.maps.event.addListener(marker, 'dragend', function(event){
  29. markerLocation();
  30. });
  31. } else{
  32.  
  33. marker.setPosition(myLatLng);
  34. }
  35. markerLocation();
  36. });
  37. }
  38.  
  39. function markerLocation(){
  40. var currentLocation = marker.getPosition();
  41. document.getElementById('lat').value = currentLocation.lat();
  42. document.getElementById('lng').value = currentLocation.lng();
  43. }
  44.  
  45. google.maps.event.addDomListener(window, 'load', initMap);
  46.  
  47. </script>
Go to the top of the page
+Quote Post
viking
post
Post #2





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Masz przecież podpięty kawał kodu na zdarzenie click...
Go to the top of the page
+Quote Post
krzesik
post
Post #3





Grupa: Zarejestrowani
Postów: 516
Pomógł: 1
Dołączył: 25.08.2012

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


Tak ma forma gdzie w pierwszym kroku wskazuję punkt który zapisuję do bazy, a w przypadku potrzeby zmiany lokalizacji chciałbym go wyświetlić (bez klikania)
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 - 00:00