Asp.net中的谷歌地图 [英] Google Map in Asp.net

查看:57
本文介绍了Asp.net中的谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在我的网站中使用谷歌地图。我需要从C#传递java脚本输入值。

在数据库中我有纬度,经度值集。我需要将此值传递给java脚本。

下面我提到了我的代码:



Hi,
I am using Google Map in My Website. I need to pass the java script input values from C#.
In Database i have set of latitude,longitude values. I need to pass this values to java script.
Below i have mentioned my code:

<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
  <title>Google Maps Multiple Markers</title> 
  <script src="http://maps.google.com/maps/api/js?sensor=false" 

          type="text/javascript"></script>
</head> 

	<body>
	<div id="map" style="width: 700px; height: 800px;"></div>
	<script id="js" type="text/javascript">
 

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 5,
      center: new google.maps.LatLng(21.7679, 78.8718),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    
	
    var markersarray = [];
	
    function clearoverlays()
    {
	if(markersarray)
	{
	    for(i in markersarray)
	    {
		markersarray[i].setMap(null);
	    }
	}
    }
    
      
    function javascript(city,latitude,longitude,count,DisName)
    {
     var infowindow = new google.maps.InfoWindow();

    var marker;

    
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(latitude,longitude),
        map: map

      });
	      markersarray.push(marker);

      google.maps.event.addListener(marker, 'click', (function(marker) {
        return function() {
        infowindow.setContent("<p>" +""+"Place : "+""+ city +"<br />" +""+"DiseaseName : "+"" +DisName+ "<br/>"+""+"Number of Patients Affected : "+""+ count+ "<br />"+
                  "</p>");
    zoom: 5,
          infowindow.open(map, marker);
        }
      })(marker));
     
    } 

    
  </script>
  
	</body>
</html>







我的C#代码是:

< br $>





My C# code is :


string[,] data = new string[arraylength, 4];
           
            data = GoogleRegions(disease, Mon); // GoogleRegions function to select the DB Details
           

            int len = data.Length;

                
             
         
            ClientScript.RegisterStartupScript(this.GetType(), "clearoverlays", "clearoverlays");

                for (int i = 0; i < len / 4; i++)
                {
                    string place = data[i, 0].ToUpper();
                    disease = disease.ToUpper();

                    

                   ClientScript.RegisterStartupScript(this.GetType(), "javascript", string.Format("javascript('{1,2,3,4,5}')",place,data[i,1],data[i,2], data[i, 3], disease),false);
}







但我没有得到地图标记。如何将值传递给上面的javascript函数?有人帮忙吗?




But i didnt get the Map Marker. How can i pass the values to above javascript function? Anyone help for this?

推荐答案

在我的项目中使用这样的东西一旦你经历了这个,你就可以从这里得到一些东西

am using like this in my project once you go through this you may get something from this
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WatchDoctorLocation.aspx.cs"
    Inherits="Inforaise.eMediTime.Web.ModalWindows.WatchDoctorLocation" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <%-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    --%>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">


(document).ready(function(){
var geocoder;
jQuery。 ajax({
类型:GET,
dataType:json,
url:http://maps.googleapis.com/maps/api/geocode/json,
数据:{'地址':'HYDERABAD','传感器':false},
成功:函数(数据){
if(data.results.length){
initialize ('<%= docLatitude%>','<%= docLongitude%>');
} else {
alert(无效地址);
}
}
});
});
函数初始化(纬度,经度){
var myLatlng = new google.maps.LatLng(纬度,经度);
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom:19,
center:myLatlng
}
var map = new google.maps.Map(document.getElementById('googleMap') ,mapOptions);
var marker = new google.maps.Marker({
position:myLatlng,
map:map,
animation:google.maps.Animation.DROP
//标题:'inforaise technologies'
});


google.maps.event.addListener(marker,'click',function(){
geocoder.geocode({'latLng':myLatlng},function(results,results,状态){
if(status == google.maps.GeocoderStatus.OK){
if(results [1]){
map.setZoom(19);
marker = new google.maps.Marker({
position:myLatlng,
map:map
});
infowindow.setContent(''+'<%= DocLocation %>'+''+','+'< br />'+ results [1] .formatted_address);
infowindow.open(map,marker);
} else {
alert('找不到结果');
}
} else {
ale rt('Geocoder因以下原因失败:'+状态);
}
});
//infowindow.open(map,marker);
});
var contentString;
var infowindow = new google.maps.InfoWindow({
content:contentString
});
var mapProp = {
center:new google.maps.LatLng(Latitude,Longitude),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
google.maps.event.addDomListener(window,'load',initialize);
}
< / script>
< style type =text / css>
#divGoogleMaps
{
身高:350px!important;
填充:0px 0px!important;
}
#googleMap
{
position:fixed!important;
background-color:none!important;
}
.gm-style-iw
{
宽度:120px!important;
身高:自动!重要;
}
< / style>
< / head>
< body>
< div id =googleMapstyle =width:100%; height:100%>
< / div>
< / body>
< / html>
(document).ready(function () { var geocoder; jQuery.ajax({ type: "GET", dataType: "json", url: "http://maps.googleapis.com/maps/api/geocode/json", data: { 'address': 'HYDERABAD', 'sensor': false }, success: function (data) { if (data.results.length) { initialize('<%=docLatitude %>', '<%=docLongitude %>'); } else { alert("Invalid Address"); } } }); }); function initialize(Latitude, Longitude) { var myLatlng = new google.maps.LatLng(Latitude, Longitude); geocoder = new google.maps.Geocoder(); var mapOptions = { zoom: 19, center: myLatlng } var map = new google.maps.Map(document.getElementById('googleMap'), mapOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, animation: google.maps.Animation.DROP //title: 'inforaise technologies' }); google.maps.event.addListener(marker, 'click', function () { geocoder.geocode({ 'latLng': myLatlng }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[1]) { map.setZoom(19); marker = new google.maps.Marker({ position: myLatlng, map: map }); infowindow.setContent('' + '<%=DocLocation %>' + '' + ',' + '<br/>' + results[1].formatted_address); infowindow.open(map, marker); } else { alert('No results found'); } } else { alert('Geocoder failed due to: ' + status); } }); //infowindow.open(map, marker); }); var contentString; var infowindow = new google.maps.InfoWindow({ content: contentString }); var mapProp = { center: new google.maps.LatLng(Latitude, Longitude), zoom: 5, mapTypeId: google.maps.MapTypeId.ROADMAP }; google.maps.event.addDomListener(window, 'load', initialize); } </script> <style type="text/css"> #divGoogleMaps { height: 350px !important; padding: 0px 0px !important; } #googleMap { position: fixed !important; background-color: none !important; } .gm-style-iw { width: 120px !important; height: auto !important; } </style> </head> <body> <div id="googleMap" style="width: 100%; height: 100%"> </div> </body> </html>








服务器中的
我正在分配经度和纬度值









in server side just am assigning the longitude and latitude values


public partial class WatchDoctorLocation : System.Web.UI.Page
   {
       public string docLongitude;
       public string docLatitude;
       public string DocLocation;

       protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               string DoctorLocation = Request.QueryString["DocLocation"];
               string[] altitudes = DoctorLocation.Split(':');
               docLongitude = altitudes[0];
               docLatitude = altitudes[1];
               DocLocation = altitudes[2];

           }

       }
   }


适用于ASP.NET的Google地图控件 - 第1部分 [ ^ ]





希望这可行。
Google Maps Control for ASP.NET - Part 1[^]


Hope This works.


这篇关于Asp.net中的谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆