Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

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





Grupa: Zarejestrowani
Postów: 174
Pomógł: 0
Dołączył: 16.05.2006
Skąd: Łódź

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


w sekcji HEAD pobieram z SQL w pętli współrzędne i otrzymuję w efekcie

  1. <script type="text/javascript">
  2. function mapa() {
  3. var opcje = {zoom: 15, center: pozycja, mapTypeId: google.maps.MapTypeId.ROADMAP}
  4. var mapa = new google.maps.Map(document.getElementById("GoogleMap"), opcje);
  5. var pozycja = new google.maps.LatLng(51.7596551014072, 19.45899602920531);
  6. var dymek = new google.maps.InfoWindow();
  7. var flaga = 'x.png';
  8.  
  9. var a_43 = new google.maps.InfoWindow ({content: '<p><span class="title">test5</span>,<br /><br />5</p>'});
  10. var b_43 = new google.maps.LatLng(51.76191289573248, 19.447795124359118);
  11. var c_43 = new google.maps.Marker({position: b_43, map: mapa, icon: flaga});
  12. google.maps.event.addListener(c_43, 'click', function() {a_43.open(mapa, c_43);});
  13.  
  14. var a_42 = new google.maps.InfoWindow ({content: '<p><span class="title">test4</span>,<br /><br />4</p>'});
  15. var b_42 = new google.maps.LatLng(51.76191289573248, 19.447795124359118);
  16. var c_42 = new google.maps.Marker({position: b_42, map: mapa, icon: flaga});
  17. google.maps.event.addListener(c_42, 'click', function() {a_42.open(mapa, c_42);});
  18.  
  19. var a_41 = new google.maps.InfoWindow ({content: '<p><span class="title">test3</span>,<br /><br />3</p>'});
  20. var b_41 = new google.maps.LatLng(51.757344065590104, 19.449125500030505);
  21. var c_41 = new google.maps.Marker({position: b_41, map: mapa, icon: flaga});
  22. google.maps.event.addListener(c_41, 'click', function() {a_41.open(mapa, c_41);});
  23.  
  24. var a_40 = new google.maps.InfoWindow ({content: '<p><span class="title">test2</span>,<br /><br />2</p>'});
  25. var b_40 = new google.maps.LatLng(51.76042542039522, 19.47418806106566);
  26. var c_40 = new google.maps.Marker({position: b_40, map: mapa, icon: flaga});
  27. google.maps.event.addListener(c_40, 'click', function() {a_40.open(mapa, c_40);});
  28.  
  29. var a_39 = new google.maps.InfoWindow ({content: '<p><span class="title">test1</span>,<br /><br />1</p>'});
  30. var b_39 = new google.maps.LatLng(51.7574503227045, 19.473801822967516);
  31. var c_39 = new google.maps.Marker({position: b_39, map: mapa, icon: flaga});
  32. google.maps.event.addListener(c_39, 'click', function() {a_39.open(mapa, c_39);});
  33.  
  34. }


na mapie mam ładnie pokazane markery z opisami pojawiającymi się w dymkach po kliknięciu na nie, następnie w sekcji BODY tworze w pętli linki

  1. <ol>
  2. <li><strong><a href="java script:google.maps.event.addListener(d_43, 'click', function() {b_43.open(mapa, d_43);});">test5</a></strong> (5)</li>
  3. <li><strong><a href="java script:google.maps.event.addListener(d_42, 'click', function() {b_42.open(mapa, d_42);});">test4</a></strong> (4)</li>
  4. <li><strong><a href="java script:google.maps.event.addListener(d_41, 'click', function() {b_41.open(mapa, d_41);});">test3</a></strong> (3)</li>
  5. <li><strong><a href="java script:google.maps.event.addListener(d_40, 'click', function() {b_40.open(mapa, d_40);});">test2</a></strong> (2)</li>
  6. <li><strong><a href="java script:google.maps.event.addListener(d_39, 'click', function() {b_39.open(mapa, d_39);});">test1</a></strong> (1)</li>
  7. </ol>


mam prośbę o podpowiedź co wstawić w HREF aby wyświetlić dany marker na mapie?

Ten post edytował piotrd 8.08.2012, 13:07:49
Go to the top of the page
+Quote Post
mls
post
Post #2





Grupa: Zarejestrowani
Postów: 677
Pomógł: 89
Dołączył: 31.08.2003
Skąd: Warszawa

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


Zmienna jest zdefiniowana wewnątrz funkcji i ma zasięg lokalny. Wobec tego nie widać jej nigdzie poza funkcją "mapa".
Go to the top of the page
+Quote Post
piotrd
post
Post #3





Grupa: Zarejestrowani
Postów: 174
Pomógł: 0
Dołączył: 16.05.2006
Skąd: Łódź

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


ok rozumiem, ale gdy tworzę nową funkcję po

  1. function mapa() {
  2. ...
  3. }


zawierającą

  1. function link() {
  2. google.maps.event.addListener(c_39, 'click', function() {a_39.open(mapa, c_39);});
  3. }


wtedy i tak nie działa
Go to the top of the page
+Quote Post
Pawel_W
post
Post #4





Grupa: Zarejestrowani
Postów: 1 675
Pomógł: 286
Dołączył: 15.06.2009
Skąd: Wieliczka

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


  1. var mapa;
  2. function mapa(){}
  3. function link(){}

i wtedy nie zapominj z mapa powypieprzać te vary (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
piotrd
post
Post #5





Grupa: Zarejestrowani
Postów: 174
Pomógł: 0
Dołączył: 16.05.2006
Skąd: Łódź

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


za piękne aby było prawdziwe, męczę się z tym już 3 dzień bez efektów
przeniosłem vary poza funkcję mapa() ale linki nadal nie działają

cały html

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="pl-PL">
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <link rel="stylesheet" href="./style.css" type="text/css" media="screen" />
  6. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  7. <script type="text/javascript">
  8. var pozycja = new google.maps.LatLng(51.7596551014072, 19.45899602920531);
  9. var opcje = {zoom: 14, center: pozycja, mapTypeId: google.maps.MapTypeId.ROADMAP}
  10. var marker = new google.maps.Marker({position: pozycja, draggable: true});
  11. var dymek = new google.maps.InfoWindow();
  12. var flaga = 'x.png';
  13. var mapa;
  14.  
  15. var a_45, b_45, c_45;
  16. var a_44, b_44, c_44;
  17. var a_43, b_43, c_43;
  18.  
  19. function mapa() {
  20. mapa = new google.maps.Map(document.getElementById("GoogleMap"), opcje);
  21.  
  22. a_45 = new google.maps.InfoWindow ({content: '<p><span class="title">test</span><br /><br />test</p>'});
  23. b_45 = new google.maps.LatLng(51.75694559918423, 19.493585796661364);
  24. c_45 = new google.maps.Marker({position: b_45, map: mapa, icon: flaga});
  25. google.maps.event.addListener(c_45, 'click', function() {a_45.open(mapa, c_45);});
  26.  
  27. a_44 = new google.maps.InfoWindow ({content: '<p><span class="title">test</span><br /><br />test</p>'});
  28. b_44 = new google.maps.LatLng(51.75604239564689, 19.499765606231676);
  29. c_44 = new google.maps.Marker({position: b_44, map: mapa, icon: flaga});
  30. google.maps.event.addListener(c_44, 'click', function() {a_44.open(mapa, c_44);});
  31.  
  32. a_43 = new google.maps.InfoWindow ({content: '<p><span class="title">test</span><br /><br />test</p>'});
  33. b_43 = new google.maps.LatLng(51.7535983425582, 19.486805172271715);
  34. c_43 = new google.maps.Marker({position: b_43, map: mapa, icon: flaga});
  35. google.maps.event.addListener(c_43, 'click', function() {a_43.open(mapa, c_43);});
  36. }
  37. </head>
  38.  
  39. <body onload="mapa();">
  40. <div id="GoogleMap"></div>
  41. <div id="form" style="float: left; margin-left: 20px;">
  42. </div>
  43. <div id="osoby" style="float: left; margin-left: 20px;">
  44. <p>x:</p>
  45. <ol>
  46. <li><strong><a href="#" onclick="java script:google.maps.event.addListener(c_45,'click',function(){a_45.open(mapa,c_45);return: false;});">test</a></strong>: test</li>
  47. <li><strong><a href="#" onclick="java script:google.maps.event.addListener(c_44,'click',function(){a_44.open(mapa,c_44);return: false;});">test</a></strong>: test</li>
  48. <li><strong><a href="#" onclick="java script:google.maps.event.addListener(c_43,'click',function(){a_43.open(mapa,c_43);return: false;});">test</a></strong>: test</li>
  49. </ol>
  50. </div>
  51. </body>
  52. </html>
  53.  


Ten post edytował piotrd 9.08.2012, 12:36:55
Go to the top of the page
+Quote Post
Pawel_W
post
Post #6





Grupa: Zarejestrowani
Postów: 1 675
Pomógł: 286
Dołączył: 15.06.2009
Skąd: Wieliczka

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


od kiedy w onclick podaje się kod po java script: (IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
piotrd
post
Post #7





Grupa: Zarejestrowani
Postów: 174
Pomógł: 0
Dołączył: 16.05.2006
Skąd: Łódź

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


to
  1. <a href="#" onclick="google.maps.event.addListener(c_47,'click',function(){a_47.open(mapa,c_47);return: false;});">

i to
  1. a href="java script:google.maps.event.addListener(c_47,'click',function(){a_47.open(mapa,c_47);return: false;});">

nie działa

Ten post edytował piotrd 9.08.2012, 13:23:40
Go to the top of the page
+Quote Post
d3ut3r
post
Post #8





Grupa: Zarejestrowani
Postów: 709
Pomógł: 176
Dołączył: 24.10.2010

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


o coś takiego chodzi ? bo nie jestem pewien czy rozumiem twój problem (IMG:style_emoticons/default/smile.gif)

http://jsfiddle.net/9pDmV/
Go to the top of the page
+Quote Post
piotrd
post
Post #9





Grupa: Zarejestrowani
Postów: 174
Pomógł: 0
Dołączył: 16.05.2006
Skąd: Łódź

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


dokładnie tak, o to chodzi
Go to the top of the page
+Quote Post
d3ut3r
post
Post #10





Grupa: Zarejestrowani
Postów: 709
Pomógł: 176
Dołączył: 24.10.2010

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


poczytaj o google.maps.event.trigger
Go to the top of the page
+Quote Post
piotrd
post
Post #11





Grupa: Zarejestrowani
Postów: 174
Pomógł: 0
Dołączył: 16.05.2006
Skąd: Łódź

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


stwierdzam że to jest awykonalne bo nie można odwołać się to funkcji która już została zainicjowana przez <body onload>
musze wszystko napisac od nowa i w funkcji mapa() wykonać pętle linków które później wyświetlę na stronie
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: 25.08.2025 - 02:46