[英]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.