位置Java脚本在部署后将停止工作 [英] Location Java Script ceases to work when deployed

查看:85
本文介绍了位置Java脚本在部署后将停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在登录屏幕上本地调试网站时,我会看到地图所在的位置,并且有两个充满我的经度和纬度的文本字段,但是当我部署网站时,该字段将停止工作.奇怪的是,当我去年部署它时,它运行良好.

When I debug my website locally in the login screen I see the map where I am and there are two textfields filled with my longitude and latitude, but when I deploy my website this ceases to work. The weird thing is that when I deployed it last year it worked perfectly.

这是登录页面的视图:

@using WebApplication2.Models
@model LoginViewModel

@{
    ViewBag.Title = "Log in";
}

<h2>@ViewBag.Title.</h2>
<div class="row">
    <div class="col-md-5">
        <section id="loginForm">
            @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) {
                @Html.AntiForgeryToken()
                <h4>Use a local account to log in.</h4>
                <hr />
                @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                <div class="form-group">
                    @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <div class="checkbox">
                            @Html.CheckBoxFor(m => m.RememberMe)
                            @Html.LabelFor(m => m.RememberMe)
                        </div>
                    </div>
                </div>
                <input type="hidden" id="coordinates" name="coordinates">

                <div class="form-group">
                    <div class="col-md-10">
                        @Html.HiddenFor(m => m.Latitude)
                        @Html.EditorFor(m => m.Longitude)
                        @Html.EditorFor(m => m.Accuracy)
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Log in" class="btn btn-default" />
                    </div>
                </div>

                <p>
                    @Html.ActionLink("Register as a new user", "Register")
                </p>
                @* Enable this once you have account confirmation enabled for password reset functionality
                    <p>
                        @Html.ActionLink("Forgot your password?", "ForgotPassword")
                    </p>*@



            }
        </section>
    </div>

    @*<div class="col-md-4">
            <section id="socialLoginForm">
                @Html.Partial("_ExternalLoginsListPartial", new ExternalLoginListViewModel { Action = "ExternalLogin", ReturnUrl = ViewBag.ReturnUrl })
            </section>
        </div>*@
    <div class="col-md-4">
        <section>
            <h2>Contact administrator if its not your current location: </h2>
            <div id="map" style="height: 253px ; width: 253px" />
        </section>
    </div>

</div>

@section Scripts {
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script>
        var options = {
            enableHighAccuracy: true,
            timeout: 5000,
            maximumAge: 0
        };
        alert('aaa');
        var x = document.getElementById("coordinates");
        var latitude = document.getElementById("Latitude");
        var longitude = document.getElementById("Longitude");
        var accuracy = document.getElementById("Accuracy");
        function getLocation() {
            if (navigator.geolocation) {
                var position = navigator.geolocation.getCurrentPosition(showPosition, null, options);

            } else {
                x.innerHTML = "Geolocation is not supported by this browser.";
            }
        }
        function showPosition(position) {
            x.value = "Latitude: " + position.coords.latitude + "Longitude: " + position.coords.longitude + "Accuracy: " + position.coords.accuracy + " meters";
            latitude.value = position.coords.latitude;
            longitude.value = position.coords.longitude;
            accuracy.value = position.coords.accuracy;
            InitializeMap(position)
        }
        var map;
        var geocoder;
        function InitializeMap(position) {
            var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            var mapOptions =
            {
                zoom: 16,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                disableDefaultUI: true
            };
            map = new google.maps.Map(document.getElementById("map"), mapOptions);

            var marker = new google.maps.Marker({
                position: latlng,
                title: 'Hello World!'
            });
            marker.setMap(map);

        }
        window.addEventListener('load', getLocation);
    </script>
    @Scripts.Render("~/bundles/jqueryval")
}

这是它在本地的外观:

,您会看到它在网络上的外观: http ://informatyka4445-001-site1.itempurl.com/Account/Login?ReturnUrl =%2F

and you can see how it looks in the web: http://informatyka4445-001-site1.itempurl.com/Account/Login?ReturnUrl=%2F

问题:为什么将地图部署到Web时看不到地图.

Question: Why the map is not visible when I deployed it to the web.

登录名是:admin@admin.pl通过是:TestPass44!它完全是您可以使用的模拟数据.

The login is : admin@admin.pl pass is : TestPass44! it is totally mock up data you can play with it.

推荐答案

这是启动您的网站后在控制台中显示的内容:

This is what I get in the console after launching your website:

getCurrentPosition()和watchPosition()在不安全的情况下不再起作用 起源.要使用此功能,您应该考虑切换您的 到安全来源(例如HTTPS)的应用程序.看 链接有关更多详细信息.

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See link for more details.

将您的网站切换为https将有帮助

Switching your website to https will help

这篇关于位置Java脚本在部署后将停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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