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<!DOCTYPE html>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <link href="default.css" rel="stylesheet"> #directions-panel {
height: 100%;
float: right;
width: 390px;
overflow: auto;
}
#map-canvas {
margin-right: 400px;
}
#control {
background: #fff;
padding: 5px;
font-size: 14px;
font-family: Arial;
border: 1px solid #ccc;
box-shadow: 0 2px 2px rgba(33, 33, 33, 0.4);
display: none;
}
@media print {
#map-canvas {
height: 500px;
margin: 0;
}
#directions-panel {
float: none;
width: auto;
}
}
<script src="https://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <script type="text/javascript"> var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var latlng = new google.maps.LatLng(37.890054, -4.778567);
var start = latlng;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: latlng
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directions-panel'));
if(document.getElementById('end').value == ''){
var marker = new google.maps.Marker({
// definimos la poisicion de nuestra marca en el mapa
position: map.getCenter(),
map: map,
// titulo que aparecera cuando pongamos el cursor encima
title: 'Titulo',
// aqui encontraras muchos tipos de iconos:
//http://gmaps-samples.googlecode.com/svn/trunk/markers/
icon: 'http://www.dondelocompro.es/img/nuevas/home/ico_pincho.png',
cursor: 'default',
draggable: false
});
}
var control = document.getElementById('control');
control.style.display = 'block';
map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);
}
function calcRoute() {
var end = document.getElementById('end').value + ' ,españa';
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
<input type="text" id="start"> <input type="text" id="end">
<div id="directions-panel"></div>
A ver si alguien sabe como se podria quitar al pulsar el boton,
Un saludo!!