简体   繁体   中英

how to set marker location in google map when location is loaded into a textbox without using autocomplete or marker events?

enter code hereif ( vm.TaskLocation.length !=0)
        {
           alert("haii");
             var place = vm.TaskLocation;
            document.getElementById('latitudeId').value =place.geometry.location.lat();
            document.getElementById('longitudeId').value =place.geometry.location.lng();
            marker.setPosition(place.geometry.location);
            marker.setVisible(true);

        }

location is in vm.TaskLocation and textbox is filled with this location during the editing section but marker location is not changing

i got answer

geocoder = new google.maps.Geocoder();
    var taskLocation = document.getElementById("taskLocation");
    //function in case of edit task.set map according to location in text box
    if(taskLocation  != 0)
    {
        var loc=[];
        // next line creates asynchronous request
        geocoder.geocode( { 'address': vm.TaskLocation}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                loc[0]=results[0].geometry.location.lat();
                loc[1]=results[0].geometry.location.lng();
                var mapOptions = {
                    center: new google.maps.LatLng(loc[0], loc[1]),
                    zoom: 15
                };
                map = new google.maps.Map(document.getElementById('map'),
                              mapOptions);
                marker = new google.maps.Marker({
                    position: new google.maps.LatLng(loc[0], loc[1]),
                    map: map,
                });
                document.getElementById('latitudeId').value =loc[0];
                document.getElementById('longitudeId').value =loc[1];
            } 
        }else {
                alert("Geocode was not successful for the following reason: " + status);
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM