Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/07/2013, 04:37
franjgg
 
Fecha de Ingreso: marzo-2007
Mensajes: 751
Antigüedad: 17 años, 2 meses
Puntos: 4
Respuesta: Como añadir a este codigo que muestre una marca de google maps "casi esta"

He conseguido poner la marca, la unica cosa es que no la quita cuando enviamos la direccion, he incluido un if: if(document.getElementById('end').value == ''){

Pero no la llega a quitar

El codigo:

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2.   <head>
  3.     <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  4.     <meta charset="utf-8">
  5.     <title>Displaying text directions with <code>setPanel()</code></title>
  6.     <link href="default.css" rel="stylesheet">
  7.     <style>
  8.       #directions-panel {
  9.         height: 100%;
  10.         float: right;
  11.         width: 390px;
  12.         overflow: auto;
  13.       }
  14.  
  15.       #map-canvas {
  16.         margin-right: 400px;
  17.       }
  18.  
  19.       #control {
  20.         background: #fff;
  21.         padding: 5px;
  22.         font-size: 14px;
  23.         font-family: Arial;
  24.         border: 1px solid #ccc;
  25.         box-shadow: 0 2px 2px rgba(33, 33, 33, 0.4);
  26.         display: none;
  27.       }
  28.  
  29.       @media print {
  30.         #map-canvas {
  31.           height: 500px;
  32.           margin: 0;
  33.         }
  34.  
  35.         #directions-panel {
  36.           float: none;
  37.           width: auto;
  38.         }
  39.       }
  40.     </style>
  41.     <script src="https://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>    
  42.     <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
  43.     <div id="map-canvas"></div>
  44.     <script type="text/javascript">
  45. var directionsDisplay;
  46. var directionsService = new google.maps.DirectionsService();
  47. var latlng = new google.maps.LatLng(37.890054, -4.778567);
  48. var start = latlng;
  49.  
  50. function initialize() {
  51.   directionsDisplay = new google.maps.DirectionsRenderer();
  52.   var mapOptions = {
  53.     zoom: 14,
  54.     mapTypeId: google.maps.MapTypeId.ROADMAP,
  55.     center: latlng
  56.   };
  57.   var map = new google.maps.Map(document.getElementById('map-canvas'),
  58.       mapOptions);
  59.   directionsDisplay.setMap(map);
  60.   directionsDisplay.setPanel(document.getElementById('directions-panel'));
  61.  
  62.   if(document.getElementById('end').value == ''){
  63.  
  64.         var marker = new google.maps.Marker({
  65.             // definimos la poisicion de nuestra marca en el mapa
  66.             position: map.getCenter(),
  67.             map: map,
  68.             // titulo que aparecera cuando pongamos el cursor encima
  69.             title: 'Titulo',
  70.             // aqui encontraras muchos tipos de iconos:
  71.             //http://gmaps-samples.googlecode.com/svn/trunk/markers/
  72.  
  73.             icon: 'http://www.dondelocompro.es/img/nuevas/home/ico_pincho.png',
  74.             cursor: 'default',
  75.             draggable: false
  76.         });  
  77. }
  78.   var control = document.getElementById('control');
  79.   control.style.display = 'block';
  80.   map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87. function calcRoute() {
  88.  
  89.   var end = document.getElementById('end').value + ' ,españa';
  90.   var request = {
  91.     origin: start,
  92.     destination: end,
  93.     travelMode: google.maps.TravelMode.WALKING
  94.   };
  95.   directionsService.route(request, function(response, status) {
  96.     if (status == google.maps.DirectionsStatus.OK) {
  97.       directionsDisplay.setDirections(response);
  98.     }
  99.   });
  100. }
  101.  
  102. google.maps.event.addDomListener(window, 'load', initialize);
  103.  
  104.     </script>
  105.   </head>
  106.   <body>
  107.     <div id="control">
  108.  
  109. <input type="text" id="start">
  110. <input type="text" id="end">
  111.  
  112. <button onclick="calcRoute();">enviar</button>
  113.  
  114.  
  115.  
  116.     </div>
  117.     <div id="directions-panel"></div>
  118.  
  119.   </body>
  120. </html>

A ver si alguien sabe como se podria quitar al pulsar el boton,

Un saludo!!

Última edición por franjgg; 16/07/2013 a las 04:57