开发者

How do I alert the lat and long of the Google Maps, when the market is dragged?

This is my code. But I don't know how to use the Market dragend event. What do you add to the event listener so that an alert pops up whenever the marker is dragged to a new location?

var geocoder = new google.maps.Geocoder();
        var myLatlng = new google.maps.LatLng(39.97389, -23.968563);
        var myOptions = {
        zoom: 15,
        center: myLatlng,
        mapTypeControl:false,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        scrollwheel:false,
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        $("#map_canvas").hide();

        $("#geocodesubmit").click(function(){
            $("#id_lat").val("");
            $("#id_long").val("");
            var address = $("#id_address_input").val();            geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                $("#badlocation_holder").hide();                $("#map_canvas").show();
                $("#map_canvas_holder").show().css("background-color", "#E6E6FA").animate({"
background-color":"#f5f5f5"}, 800);
                ;
                var map = new google.maps.Map(document.getElementById("map_canvas"), myOptio
ns);  
                map.setCenter(results[0].geometry.location开发者_JAVA技巧);
                $("#id_lat").val(results[0].geometry.location.lat());
                $("#id_long").val(results[0].geometry.location.lng());
                var marker = new google.maps.Marker({
                    map: map, 
                    position: results[0].geometry.location,
                    draggable:true
                });              } else {
                    $("#id_lat").val("");
                    $("#id_long").val("");
                  $("#map_canvas_holder").hide();
                  $("#badlocation_holder").show().css("background-color","#F08080").animate(
{"background-color":"#f5f5f5"},800);
              }
            });
            return false;
        });

        google.maps.event.addListener(marker, "dragend", function(e){

        });


var oldLat = marker.getPosition().lat();
var oldLng = marker.getPosition().lng();

google.maps.event.addListener(marker, "dragend", function(e){
 var newLat = marker.getPosition().lat();
 var newLng = marker.getPosition().lng();

 if(oldLat != newLat || oldLng != newLng)
  alert("its changed");
  // or $("div#modal").html("its changed !!").show();

 oldLat = newLat;
 oldLng = newLng;
});

and if you want to alert, easiest way is just use regular modal popup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜