HTTPS调用百度地图API提示“BMap未定义, This request has been blocked; the content must be served over HTTPS.,was

浏览器 解决方案 转自 新浪博客 http://blog.sina.com.cn/s/blog_7191ed320102vhgz.html

 

 This request has been blocked; the content must be served over HTTPS.

was loaded over HTTPS, but requested an insecure script 

   public ActionResult GetAddress(string lat, string lng)
        {
            string strBuff = "";
            Uri httpURL = new Uri(string.Format("http://api.map.baidu.com/geocoder/v2/?ak=6934f6bf0a1fe131d75b956f9463831f&location={0},{1}&output=json&pois=0&coordtype=wgs84ll", lat, lng));
            ///HttpWebRequest类继承于WebRequest,并没有自己的构造函数,需通过WebRequest的Creat方法 建立,并进行强制的类型转换   
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(httpURL);
            ///通过HttpWebRequest的GetResponse()方法建立HttpWebResponse,强制类型转换   
            HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse();
            ///GetResponseStream()方法获取HTTP响应的数据流,并尝试取得URL中所指定的网页内容   
            ///若成功取得网页的内容,则以System.IO.Stream形式返回,若失败则产生ProtoclViolationException错 误。在此正确的做法应将以下的代码放到一个try块中处理。这里简单处理   
            Stream respStream = httpResp.GetResponseStream();
            ///返回的内容是Stream形式的,所以可以利用StreamReader类获取GetResponseStream的内容,并以   
            //StreamReader类的Read方法依次读取网页源程序代码每一行的内容,直至行尾(读取的编码格式:UTF8)   
            StreamReader respStreamReader = new StreamReader(respStream, Encoding.UTF8);
            strBuff = respStreamReader.ReadToEnd();

            return Json(strBuff, JsonRequestBehavior.AllowGet);
        }
    window.onload = function () {
            if (window.navigator.geolocation) {
                var options = {
                    enableHighAccuracy: true,
                };
                var currentposition = window.navigator.geolocation.getCurrentPosition(handleSuccess, handleError, options);

            } else {

            }
        }
        function handleSuccess(position) {
            // 获取到当前位置经纬度  本例中是chrome浏览器取到的是google地图中的经纬度
            var lng = position.coords.longitude;
            var lat = position.coords.latitude;
          
            $.ajax({
                type: "GET",
                cache: false,
                url: "/MobileWebApp/AnnualMeeting/ContentsManager/GetAddress?lat=" + lat + "&lng=" + lng,
                //data: { strCparent: $("#Equipment_ID").val() },
                dataType: "json",
                //jsonp: "callback",
                //jsonpCallback: "OnGetMemberSuccessByjsonp",
                success: function (data) {
                    //处理data
                    data = JSON.parse(data);
                    document.getElementById("startplace").value = data.result.formatted_address
                }
            });
        }
        function handleError(error) {

        }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值