Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript][PHP]Wyświetlanie markera na mapie Google
trifek
post 3.11.2018, 17:41:36
Post #1





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

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


Witam.
Mam taki kod:
  1. <?php
  2. $lat = '52.29924142';
  3. $lng = '19.18350241';
  4. ?>
  5.  
  6. <script type="text/javascript">
  7. //<![CDATA[
  8.  
  9. var map = null;
  10. var marker = null;
  11.  
  12. var infowindow = new google.maps.InfoWindow(
  13. {
  14. size: new google.maps.Size(150, 50)
  15. });
  16.  
  17. function createMarker(latlng, name, html) {
  18. var contentString = html;
  19. var marker = new google.maps.Marker({
  20. position: latlng,
  21. map: map,
  22. zIndex: Math.round(latlng.lat() * -100000) << 5
  23. });
  24.  
  25. google.maps.event.addListener(marker, 'click', function () {
  26. infowindow.setContent(contentString);
  27. infowindow.open(map, marker);
  28. });
  29. google.maps.event.trigger(marker, 'click');
  30. return marker;
  31. }
  32.  
  33.  
  34. function initialize() {
  35. var myOptions = {
  36. zoom: 7,
  37. center: new google.maps.LatLng(<?php echo $lat;?>, <?php echo $lng;?>),
  38. mapTypeControl: true,
  39. mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
  40. navigationControl: true,
  41. mapTypeId: google.maps.MapTypeId.ROADMAP
  42. }
  43. map = new google.maps.Map(document.getElementById("map_canvas"),
  44. myOptions);
  45.  
  46. google.maps.event.addListener(map, 'click', function () {
  47. infowindow.close();
  48. });
  49.  
  50. google.maps.event.addListener(map, 'click', function (event) {
  51. if (marker) {
  52. marker.setMap(null);
  53. marker = null;
  54. }
  55. marker = createMarker(event.latLng, "name", "<b>Wskaż lokalizację obiektu</b><br>" + event.latLng);
  56.  
  57. $(".lat").val(event.latLng.lat);
  58. $(".lng").val(event.latLng.lng);
  59. });
  60.  
  61. }
  62.  
  63.  
  64. //]]>
  65. </script>
  66.  
  67. <input type="hidden" name="lat" value="<?php echo $lat;?>" class="lat">
  68. <input type="hidden" name="lng" value="<?php echo $lng;?>" class="lng">
  69. <div id="map_canvas" style="width: 100%; height: 500px"></div>
  70.  



Mój obecny kod wyświetla mapę google i po kliknięciu na mapie dodaje znacznik wraz z informacjami o współrzędnych geograficznych. Współrzędne są dodawane do 2 inputów.

W zmiennych $lat i $lng mam zapisane współrzędne z MySQL.

Problem polega na tym, że znacznik jest wyświetlany tylko po pierwszym kliknięciu na mapie.

Chciałbym zobaczyć znacznik na mapie także po załadowaniu strony internetowej.


Wie ktoś może jak to zrobić?
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: 28.03.2024 - 20:53