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中,文本框在编辑部分填充此位置但标记位置未更改
答案 0 :(得分:0)
我得到了答案
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);
}