错误:无效密钥或未授权的网址映射

时间:2015-07-31 18:09:34

标签: javascript html css asp.net google-maps

我正在使用ASP.Net网络应用程序,并且我试图在我的Registration.aspx页面中查看谷歌地图,以使用户找到他在地图中的位置。但是当我尝试更改地图CSS时,我得到了这个error invalid key or unauthorized url map,地图就会消失!而且我仍然无法将地图CSS位置更改为适合我的布局页面!如果我在CSS中做任何更改,一切都会消失!我知道这是一个愚蠢的问题,但问题是什么!为什么我无法对CSS进行任何更改以修复页面中的位置?

地图代码:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../demoengine/demoengine.min.css" rel="stylesheet">
    <script src="../demoengine/demoengine.min.js" defer></script>
    <title>Google Maps: Latitude-Longitude Finder Tool</title>
    <style>
        #map-search { position: absolute; top: 44px; left: 8px; right: 8px; }
        #search-txt { float: left; width: 60%; }
        #search-btn { float: left; width: 19%; }
        #detect-btn { float: right; width: 19%; }
        #map-canvas { position: absolute; top: 74px; bottom: 60px; left: 8px; right: 8px; }
        #map-output { position: absolute; bottom: 8px; left: 8px; right: 8px; }
        #map-output a { float: right; }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <div id="map-search">
        <input id="search-txt" type="text" value="Disneyland, 1313 S Harbor Blvd, Anaheim, CA 92802, USA" maxlength="100">
        <input id="search-btn" type="button" value="Locate Address">
        <input id="detect-btn" type="button" value="Detect Location" disabled>
    </div>
    <div id="map-canvas"></div>
    <div id="map-output"></div>
    <script type="text/javascript">
        /*
         * Google Maps: Latitude-Longitude Finder Tool
         * http://salman-w.blogspot.com/2009/03/latitude-longitude-finder-tool.html
         */
        function loadmap() {
            // initialize map
            var map = new google.maps.Map(document.getElementById("map-canvas"), {
                center: new google.maps.LatLng(33.808678, -117.918921),
                zoom: 13,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            });
            // initialize marker
            var marker = new google.maps.Marker({
                position: map.getCenter(),
                draggable: true,
                map: map
            });
            // intercept map and marker movements
            google.maps.event.addListener(map, "idle", function() {
                marker.setPosition(map.getCenter());
                document.getElementById("map-output").innerHTML = "Latitude:  " + map.getCenter().lat().toFixed(6) + "<br>Longitude: " + map.getCenter().lng().toFixed(6) + "<a href='https://www.google.com/maps?q=" + encodeURIComponent(map.getCenter().toUrlValue()) + "' target='_blank'>Go to maps.google.com</a>";
            });
            google.maps.event.addListener(marker, "dragend", function(mapEvent) {
                map.panTo(mapEvent.latLng);
            });
            // initialize geocoder
            var geocoder = new google.maps.Geocoder();
            google.maps.event.addDomListener(document.getElementById("search-btn"), "click", function() {
                geocoder.geocode({ address: document.getElementById("search-txt").value }, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        var result = results[0];
                        document.getElementById("search-txt").value = result.formatted_address;
                        if (result.geometry.viewport) {
                            map.fitBounds(result.geometry.viewport);
                        } else {
                            map.setCenter(result.geometry.location);
                        }
                    } else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
                        alert("Sorry, geocoder API failed to locate the address.");
                    } else {
                        alert("Sorry, geocoder API failed with an error.");
                    }
                });
            });
            google.maps.event.addDomListener(document.getElementById("search-txt"), "keydown", function(domEvent) {
                if (domEvent.which === 13 || domEvent.keyCode === 13) {
                    google.maps.event.trigger(document.getElementById("search-btn"), "click");
                }
            });
            // initialize geolocation
            if (navigator.geolocation) {
                google.maps.event.addDomListener(document.getElementById("detect-btn"), "click", function() {
                    navigator.geolocation.getCurrentPosition(function(position) {
                        map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
                    }, function() {
                        alert("Sorry, geolocation API failed to detect your location.");
                    });
                });
                document.getElementById("detect-btn").disabled = false;
            }
        }
    </script>
    <script src="//maps.googleapis.com/maps/api/js?v=3&amp;sensor=false&amp;key=AIzaSyBs1MVxS8kIxL9BXrxYE0lfvDP-iF_cmeA&amp;callback=loadmap" defer></script>
</html>
</asp:Content>

0 个答案:

没有答案