Javascript 当位置加载到文本框中而不使用自动完成或标记事件时,如何在google地图中设置标记位置?

Javascript 当位置加载到文本框中而不使用自动完成或标记事件时,如何在google地图中设置标记位置?,javascript,Javascript,位置在vm.TaskLocation中,在编辑部分,文本框中填充了此位置,但标记位置没有改变我得到了答案 enter code hereif ( vm.TaskLocation.length !=0) { alert("haii"); var place = vm.TaskLocation; document.getElementById('latitudeId').value =place.geometry

位置在vm.TaskLocation中,在编辑部分,文本框中填充了此位置,但标记位置没有改变

我得到了答案

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);

        }
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);
            }