浏览器 解决方案 转自 新浪博客 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) {
}