使用c#停止google.maps.event.addDomListener [英] stop google.maps.event.addDomListener using c#
问题描述
我有一个页面,我从数据库中获取用户值并在页面上显示。我在同一页面中有一个谷歌地图,根据我提取的数据显示用户位置。现在这个地图在我的窗口加载时启动,当我有结果值时,一切正常。但是,如果我没有值,地图正在加载并给我地理编码错误。我很简单,当我没有结果时,地图不应该加载。如何使用C#代码停止它。
I have one page in which i am fetching user values from database and show on page. I have one google map in the same page which is showing user location according to data i am fetching. Now this map is launch every time when my window loads and when i have result value then everything is working fine. But if i have no values still the map is loading and gives me geocode error. I simple want when i have no result then the map should not load. How to stop it by using C# code.
google.maps.event.addDomListener(window, 'load', first);
function first()
{
if (lat == "" || lon == "") {
InitializeMap2();
}
}
function GoogleGeocode() {
geocoder = new google.maps.Geocoder();
this.geocode = function (address, callbackFunction) {
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var result = {};
result.latitude = results[0].geometry.location.lat();
result.longitude = results[0].geometry.location.lng();
callbackFunction(result);
} else {
alert("Geocode was not successful for the following reason: " + status);
callbackFunction(null);
}
});
};
}
function InitializeMap2() {
var g = new GoogleGeocode();
var address = pincode;
g.geocode(address, function(data) {
// i am not writing the whole function.
});
}
while (reader.Read())
{
found = true;
lbl_iam.Text = reader["iamdetail"].ToString();
lbl_adid.Text = reader["ad_id"].ToString();
lat = reader["latitude"].ToString();
lon = reader["longitude"].ToString();
}
if (!found)
{
//here i want to code to stop google map load
}
推荐答案
我这样做了我的地图,以避免在所选字段中没有结果/没有条目的情况下显示错误代码。但是如果没有填充字段的搜索结果,我觉得你应该至少向用户显示地图没有填充的原因。
I did my maps like this to avoid the error code displaying if there is no results/ no entry made in the selected fields. But if there is no result from a search with the fields populated I feel you should at least show the users why the map did not populate.
function codeAddress(mapdir) {
address = document.getElementById("LocAddress1").value + " " + document.getElementById("LocAddress2").value + " " + document.getElementById("LocTown").value;
if (geocoder != null) {
if (address != " ") {
if (mapdir != " ") {
address = mapdir;
geocoder.geocode({ 'address': address }, function (results, status) {
marker.setMap(null);
if (status == google.maps.GeocoderStatus.OK) {
document.getElementById("lblGeoLocation").innerHTML = results[0].geometry.location;
document.getElementById("StaticMap").value = results[0].geometry.location;
map.setCenter(results[0].geometry.location);
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
if (status == "ZERO_RESULTS") {
alert('Geocode was not successful for the following reason: ' + status);
}
else {
}
}
});
}
希望这会有所帮助。
如果这不能解决问题,请告诉我,以便我可以将其删除作为答案。
Hope this helps.
If this does not solve the problem please lect me know so that I can remove this as an answer.
这篇关于使用c#停止google.maps.event.addDomListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!