Google Maps search box with dragable marker and input box
<p>I'm using google maps api and need to show a marker with a search box, this marker will use the lat and long I have on my database but will change if dragged or someone uses the search box. I managed to load the map and center it on the coordinates but it doesn’t shows the marker, after I use the search box all works.
I tried adding a marker in the beginning of the code but without success, it creates a new marker when I used the functions:</p>

<pre><code>var mapOptions = {
        zoom: zoom,
        center: LatLng,
        panControl: false,
        zoomControl: false,
        scaleControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }    

    var map = new google.maps.Map(document.getElementById('map'),mapOptions);
    var latitude = ;
    var longitude = ;
    var zoom = "+MapZoom+";

    var LatLng = new google.maps.LatLng(51.501476, ‎-0.140634);
    var marker = new google.maps.Marker({
        position: LatLng,
        map: map,
        title: '"+Latitude+"',
        draggable: true
    });
</code></pre>

<p>This is my current code, I’m sure I’m just missing something any help would be much appreciated </p>

<pre><code>function initialize() {

var markers = [];
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var defaultBounds = new google.maps.LatLngBounds(
  new google.maps.LatLng(51.501476, ‎-0.140634));
    map.fitBounds(defaultBounds);
var input = (document.getElementById('pacinput')
);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
var searchBox = new google.maps.places.SearchBox((input));
google.maps.event.addListener(searchBox, 'places_changed', function() {
var places = searchBox.getPlaces();
if (places.length == 0) {
  return;
}
for (var i = 0, marker; marker = markers[i]; i++) {
  marker.setMap(null);
}
markers = [];
var bounds = new google.maps.LatLngBounds();
for (var i = 0, place; place = places[i]; i++) {

  var marker = new google.maps.Marker({
    draggable: true,
    map: map,

    title: place.name,
    position: place.geometry.location
  });
  // drag response
  google.maps.event.addListener(marker, 'dragend', function(e) {
    displayPosition(this.getPosition());
  });
  // click response
  google.maps.event.addListener(marker, 'click', function(e) {
    displayPosition(this.getPosition());
  });
  markers.push(marker);
  bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
});
google.maps.event.addListener(map, 'bounds_changed', function() {
var bounds = map.getBounds();
searchBox.setBounds(bounds);
});
// displays a position on two &lt;input&gt; elements
function displayPosition(pos) {
document.getElementById('Latitude').value = pos.lat();
document.getElementById('Longitude').value = pos.lng();
}
}  
google.maps.event.addDomListener(window, 'load', initialize);
initialize();
&lt;/script&gt;"
</code></pre>