Jump to content

Recommended Posts

I have Google map using Google map API v3. what i have is a Google map in accordion which user can click and place a marker and value of lat & lon fill two text boxes on top.

 

this part is working fine with below script. but what i want now as text boxes is filled with lat & lon if user change value of lat or lon in text box marker need to change accordingly.

 

var map = null;
function initialize() {
var myLatlng = new google.maps.LatLng(25.263327,55.329895);
    var myOptions = {
        zoom: 10,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
        }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

var marker;

function placeMarker(location) {
    if ( marker ) {
        marker.setPosition(location);
    } else {
        marker = new google.maps.Marker({
        position: location,
        map: map
        });
        }
    }

google.maps.event.addListener(map, 'click', function(event) {
    placeMarker(event.latLng);
    document.getElementById("latFld").value = event.latLng.lat();
    document.getElementById("lngFld").value = event.latLng.lng();
});


  }

$(document).ready(function() {

$("#accordion").bind('accordionchange', function(event, ui) {
    if (ui.newContent.attr('id') == 'tabThree' && !map)
    {
        map = initialize();
    }
    });
    });

You'll need to add an 'onblur' listener to the textboxes, and re-calculate when the values are changed. However, as onblur doesn't kick in until the textfield has been left, you may want to instead add a button that the user can click to trigger the recalculation.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.