English 中文(简体)
页: 1
原标题:google map in asp.net page

我正试图把 go光图装在我的 v子网页上,但地图没有在网页上显示。 这里有什么错误的想法?

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="GoogleMap.aspx.vb" Inherits="GDemo.GoogleMap" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
    <title></title>

    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
    </style>

    <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

    <script>
        var geocoder;
        var map;
        function initialize() {
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var mapOptions = {
                zoom: 8,
                center: latlng
            }
            map = new google.maps.Map(document.getElementById( map-canvas ), mapOptions);
        }

        window.onload = initialize;

        function codeAddress() {
            var address = document.getElementById( address ).value;
            geocoder.geocode({  address : address }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });
                } else {
                    alert( Geocode was not successful for the following reason:   + status);
                }
            });
        }

        google.maps.event.addDomListener(window,  load , initialize);
    </script>
</head>
<body >
    <form id="form1" runat="server">
    <div id="panel">
      <input id="address" type="textbox" value="Sydney, NSW">
      <input type="button" value="Geocode" onclick="codeAddress()">
    </div>
    <div id="map-canvas"></div>
    </form>
</body>
</html>
最佳回答

当你在社会保障局使用百分比值时,特定要素的母子成分必须设定特定财产(h 8,,在这种情况下,浏览器无法计算该财产的价值。

<代码>#map-canvas的括号为form#form1,且其身高。

例如,这将发挥作用:

 html, body, form#form1, #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }

地理编码-反应中的一种投入的举例:

        function initialize() {
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var mapOptions = {
                zoom: 8,
                center: latlng
            }
            map = new google.maps.Map(document.getElementById( map-canvas ), mapOptions);
        }

        

        function codeAddress() {
            var address = document.getElementById( address ).value;
            geocoder.geocode({  address : address }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });
                    document.getElementById( form1 ).latlng.value=
                      results[0].geometry.location.toUrlValue();
                } else {
                    alert( Geocode was not successful for the following reason:   + status);
                }
            });
        }

        google.maps.event.addDomListener(window,  load , initialize);
html, body, form, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
<form id="form1" runat="server">
    <div id="panel">
      <input id="address" type="textbox" value="Sydney, NSW">
      <input type="button" value="Geocode" onclick="codeAddress()">
      <input name="latlng" />
    </div>
    <div id="map-canvas"></div>
    </form>
问题回答

        function initialize() {
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var mapOptions = {
                zoom: 8,
                center: latlng
            }
            map = new google.maps.Map(document.getElementById( map-canvas ), mapOptions);
        }

        

        function codeAddress() {
            var address = document.getElementById( address ).value;
            geocoder.geocode({  address : address }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });
                    document.getElementById( form1 ).latlng.value=
                      results[0].geometry.location.toUrlValue();
                } else {
                    alert( Geocode was not successful for the following reason:   + status);
                }
            });
        }

        google.maps.event.addDomListener(window,  load , initialize);
html, body, form, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
<form id="form1" runat="server">
    <div id="panel">
      <input id="address" type="textbox" value="Sydney, NSW">
      <input type="button" value="Geocode" onclick="codeAddress()">
      <input name="latlng" />
    </div>
    <div id="map-canvas"></div>
    </form>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签