Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]zmienne js w jednym input
maksik
post
Post #1





Grupa: Zarejestrowani
Postów: 206
Pomógł: 0
Dołączył: 26.09.2012

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


Posiadam kod google maps gdzie chciałbym aby współrzędne Lat, Lng były wpisywane do jednego pola, jednakże problem jest następujący z integracją kodu js.


Mój kod

  1.  
  2. <script>
  3. var initialLocation;
  4. var warsaw = new google.maps.LatLng(52, 21);
  5. var browserSupportFlag = new Boolean();
  6. var map, marker;
  7.  
  8. function initialize(lat, lng, zom, set) {
  9. map = new google.maps.Map(
  10. document.getElementById('map'),
  11. {
  12. panControl:true,
  13. zoomControl:true,
  14. mapTypeControl:true,
  15. scaleControl:true,
  16. streetViewControl:true,
  17. overviewMapControl:true,
  18. rotateControl:true,
  19. mapTypeId: google.maps.MapTypeId.ROADMAP,
  20. center: new google.maps.LatLng(lat, lng),
  21. zoom: zom }
  22. );
  23.  
  24. google.maps.event.addListener(map, 'click', function(event) {
  25. placeMarker(event.latLng);
  26. });
  27.  
  28. google.maps.event.addListener(map, 'zoom_changed', function(mEvent) {
  29. if(marker) populateInputs();
  30. });
  31.  
  32.  
  33.  
  34. function placeMarker(location) {
  35. if(typeof(marker) === 'undefined')
  36. {
  37. marker = new google.maps.Marker({
  38. position: location,
  39. map: map,
  40. draggable: true
  41. });
  42. }
  43. marker.setPosition(location);
  44. var markerPosition = marker.getPosition();
  45. populateInputs(markerPosition);
  46. google.maps.event.addListener(marker, "drag", function (mEvent) {
  47. populateInputs(mEvent.latLng);
  48. });
  49. }
  50.  
  51. function populateInputs(pos) {
  52. if(typeof(pos) !== 'undefined') {
  53. document.getElementById("lat").value = pos.lat();
  54. document.getElementById("lng").value = pos.lng();
  55. }
  56. document.getElementById("zoom").value = map.zoom;
  57. }
  58.  
  59. if(set == true) {
  60. placeMarker(new google.maps.LatLng(lat, lng));
  61. map.setCenter(new google.maps.LatLng(lat, lng));
  62. }
  63.  
  64. $('#update').click(function(){
  65. var lat = $('#lat').val();
  66. var lng = $('#lng').val();
  67. placeMarker(new google.maps.LatLng(lat, lng));
  68. });
  69.  
  70. }
  71. </script>
  72.  
  73. <script type="text/javascript">
  74.  
  75. var lat = '15';
  76. var zoom = '2';
  77. var set = 'false';
  78. initialize(lat, zoom, set);
  79.  
  80. </script>
  81.  
  82. <input type="text" name="lat" id="lat" value="">
  83. <input type="text" name="lng" id="lng" value="">



lecz chciałbym by ostatnie pole było wyrażone w tej postaci, czyli zmienne lat,lng wpisywane w jednym input
  1. <input type="text" name="lat_lng" id="lat_lng" value="">


sama zmiana występujących zmiennych w kodzie js "lat,lng" na jedną "lat_lng" nic nie daje, czy wie ktoś jak to zrobić?

Ten post edytował maksik 25.02.2015, 23:02:30
Go to the top of the page
+Quote Post

Posty w temacie


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 - 23:14