ASP.NET如何通过JavaScript调用高德地图

.Net技术 码拜 9年前 (2015-03-06) 2275次浏览 0个评论

我按照HTML中的Javascript调用方式,加入到aspx页面中,可是打开后,不显示地图,HTML如下:
<!DOCTYPE HTML>
<html>
<head>
<meta name=”viewport” content=”initial-scale=1.0,user-scalable=no”>
<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″>
<title>Hello,world</title>
<style type=”text/css”>
html{height:100%}
ody{height:100%;margin:0px;padding:0px}
#container{height:100%}
</style>
<script type=”text/javascript”
src=”http://webapi.amap.com/maps?v=1.3&key=yourkey”>
</script>
<script type=”text/javascript”>
function initialize(){
  var position=new AMap.LngLat(116.397428,39.90923);
  var mapObj=new AMap.Map(“container”,{
  view: new AMap.View2D({//创建地图二维视口
  center:position,//创建中心点坐标
  zoom:14, //设置地图缩放级别
  rotation:0 //设置地图旋转角度
 }),
 lang:”zh_cn”//设置地图语言类型,默认:中文简体
});//创建地图实例
}
</script>
</head>
 
<body onload=”initialize()”>
<div id=”container”></div>
</body>
</html>
我的aspx页面如下:
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”HomePage.aspx.cs” Inherits=”HomePage” %>
<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″/>
    <title>首页</title>
    <style type=”text/css”>
        html{height:100%}
        body{height:100%;margin:0px;padding:0px}
        #map{height:100%}
    </style>
    <script type=”text/javascript”src=”http://webapi.amap.com/maps?v=1.3&key=yourkey”></script>
    <script type=”text/javascript”>
        function abc() {
            var position = new AMap.LngLat(116.397428, 39.90923);
            var mapObj = new AMap.Map(“map”, {
                view: new AMap.View2D({//创建地图二维视口
                    center: position,//创建中心点坐标
                    zoom: 14, //设置地图缩放级别
                    rotation: 0 //设置地图旋转角度
                }),
                lang: “zh_cn”//设置地图语言类型,默认:中文简体
            });//创建地图实例
        }
    </script>
</head>
<body onload=”abc()”>
    <form id=”form1″ runat=”server”>
    <div>
        <div id=”map”></div>
    </div>
    </form>
</body>
</html>

ASP.NET如何通过JavaScript调用高德地图
100分
map对象放到form表单外,否则form也增加下面的样式
        html, body{height:100%;margin:0px;padding:0px}
       #form1, #map{height:100%;display:block;}
ASP.NET如何通过JavaScript调用高德地图
你的是aspx页面,发布后通过http访问是,注意你的key要替换成高德注册后的key,要不也不会高德得图不会绘制地图,key不对

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明ASP.NET如何通过JavaScript调用高德地图
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!