I am quite a novice with javascript stuff and am currently faking it till i make it lol and now ive come across a small hill that i'm struggling to get over :S.

Currently my script finds the users location and adds a pin to the map while copying LatLon to some form fields.

In addition to just zooming in on the users location i would like them to have the ability to add a custom address which is entered into a text field, geocoded and then updates the current pin on the map.

This all works, although it adds an additional pin to the map rather than updating the current pin.

I am unsure how to pass the value from the address geocoding function back into the original pin / or do i delete the original pin and add a new pin. I'm sure i can reuse some functions as well... i don't think my code is terribly efficient :/

Any way i hope a guru out there can help me out

Cheers Nick

 var geocoder;
 var map;
 var pos;


function initialize() {

geocoder = new google.maps.Geocoder();
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var address = document.getElementById("address").value;
var initialLocation;

var myOptions = {
  zoom: 12,
  center: initialLocation,
  mapTypeId: google.maps.MapTypeId.TERRAIN
}


// Try HTML5 geolocation
    if(navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var pos = new google.maps.LatLng(position.coords.latitude,
                                         position.coords.longitude);


        var marker = new google.maps.Marker({
          map: map,
          position: pos,
          title: 'Location found using HTML5.',
          draggable: true
        });



        var lat = position.coords.latitude
        var lng = position.coords.longitude
        document.getElementById('geo_latitude').value=lat;
        document.getElementById('geo_longitude').value=lng;

        google.maps.event.addListener(ma
Edit
Report