簡體   English   中英

在不使用自動完成或標記事件的情況下將位置加載到文本框中時,如何在Google地圖中設置標記位置?

[英]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);

        }

位置在vm.TaskLocation中,並且在編輯部分中文本框已用此位置填充,但標記位置未更改

我得到了答案

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM