Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Maps edit
krzesik
post 8.08.2019, 19:02:26
Post #1





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

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


mam kod który dobrze działa przy dodawaniu nowego markera na mapie,
potrzebuję go zmodyfikować tak aby można było zmienić położenie tego markera a la i lng są pobierane z BD

  1.  
  2. var map;
  3. var marker = false;
  4.  
  5. function initMap() {
  6.  
  7.  
  8.  
  9. var centerOfMap = new google.maps.LatLng(50.915, 18.818);
  10.  
  11. var options = {
  12. center: centerOfMap,
  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: clickedLocation,
  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(clickedLocation);
  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>
  48.  
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 26.04.2024 - 16:54