在我的服务器上配置JavaScript Google Maps API时出现问题
我在.NETMVC中开发了一个应用程序,它使用谷歌地图检索用户的纬度和经度,并提供植物信息。本地pc上的应用程序(即Visual Studio localhost)运行良好 我最近将该应用程序部署到一个在线服务器上,在那里地图不再显示 这是我的MVC视图代码在我的服务器上配置JavaScript Google Maps API时出现问题,javascript,c#,asp.net-mvc,google-maps,Javascript,C#,Asp.net Mvc,Google Maps,我在.NETMVC中开发了一个应用程序,它使用谷歌地图检索用户的纬度和经度,并提供植物信息。本地pc上的应用程序(即Visual Studio localhost)运行良好 我最近将该应用程序部署到一个在线服务器上,在那里地图不再显示 这是我的MVC视图代码 <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAOwftJGF5aEhCpifN-pa4A8atYYW_oW
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAOwftJGF5aEhCpifN-pa4A8atYYW_oWMY"></script>
<script type="text/javascript">
var lattt = "";
var longg = "";
var address = "";
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(p) {
var LatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
lattt = p.coords.latitude;
longg = p.coords.longitude;
var mapOptions = {
center: LatLng,
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
var marker = new google.maps.Marker({
position: LatLng,
map: map,
title: "<div style = 'height:60px;width:200px'><b>Your location:</b><br />Latitude: " + p.coords.latitude + "<br />Longitude: " + p.coords.longitude
});
google.maps.event.addListener(marker, "click", function(e) {
var infoWindow = new google.maps.InfoWindow();
infoWindow.setContent(marker.title);
infoWindow.open(map, marker);
});
var latlng = new google.maps.LatLng(lattt, longg);
var geocoder = geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
address = new String(results[1].formatted_address.toString());
$.ajax({
data: { latitude: lattt, longitude: longg, cityP: address },
url: '/User/GetCoords',
type: 'GET',
datatype: 'json',
success: function(response) {
}
});
}
}
});
});
} else {
alert('Geo Location feature is not supported in this browser.');
}
</script>
var lattt=“”;
var long=“”;
var地址=”;
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(函数(p){
var LatLng=新的google.maps.LatLng(p.coords.latitude,p.coords.longitude);
lattt=纬度;
Long=p.coords.经度;
变量映射选项={
中心:拉特林,
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“dvMap”)、mapOptions);
var marker=new google.maps.marker({
位置:LatLng,
地图:地图,
标题:“您的位置:
纬度:“+p.coords.Latitude+”
经度:“+p.coords.Latitude
});
google.maps.event.addListener(标记“单击”,函数(e){
var infoWindow=new google.maps.infoWindow();
infoWindow.setContent(marker.title);
信息窗口。打开(地图、标记);
});
var latlng=新的google.maps.latlng(lattt,long);
var geocoder=geocoder=new google.maps.geocoder();
geocoder.geocode({'latLng':latLng},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
如果(结果[1]){
address=新字符串(结果[1]。格式化的_address.toString());
$.ajax({
数据:{纬度:拉特,经度:隆格,城市:地址},
url:“/User/GetCoords”,
键入:“GET”,
数据类型:“json”,
成功:功能(响应){
}
});
}
}
});
});
}否则{
警报('此浏览器不支持地理位置功能');
}
是的,我将视图URL的引用添加到Google开发者控制台。任何形式的帮助都将不胜感激!谢谢使用https而不是http加载Google Maps API,并提供一个Maps版本作为http请求参数
默认情况下,加载的Google Maps SDK是开发版本。在应用程序中更喜欢反稳定版本 我找到了解决这个问题的办法。如果要使用getCurrentPosition()等函数,Google要求您使用https 因此,要在您的站点上安装谷歌地图,您可以使用此选项
并根据标记位置获取用户lat long 阅读使用https进行
getCurrentPosition()
Jeremi的警告,是否有解决方法?我相信https是我现在负担不起的东西。