1

也许这听起来很愚蠢,但我真的不知道如何通过<img>JavaScript 在我的 .aspx 页面中设置代码。

到目前为止我的代码:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Teste.aspx.vb"  Inherits="Teste" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

Latitude: <asp:TextBox ID="nr_latitudeTextBox" runat="server" MaxLength="12" /> <br />
Longitude: <asp:TextBox ID="nr_longitudeTextBox" runat="server" MaxLength="12" /><br />

<asp:Button ID="cmb_mapa" runat="server" Text="Mapa" OnClick="cmb_mapa_Click"/><br />
        <script language="javascript" type="text/javascript">

                function fonte(lat, lon) {
                    var src = "http://maps.google.com/maps/api/staticmap?center=lat,lon&zoom=8&size=540x280&maptype=roadmap&sensor=false";
                    testando("http://maps.google.com/maps/api/staticmap?center=lat,lon&zoom=8&size=540x280&maptype=roadmap&sensor=false", 540, 280, "Mapa");
                }

                function testando(src, width, height, alt) {
                    var img = document.createElement("img");
                    img.src = src;
                    img.width = width;
                    img.height = height;
                    img.alt = alt;
                    document.body.appendChild(img);
                }
        </script>

    <div id="img">

    </div>

</asp:Content>

部分类:

Partial Class Teste
    Inherits System.Web.UI.Page


    Protected Sub cmb_mapa_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb_mapa.Click
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "testando", "testando(" & nr_latitudeTextBox.Text & "," & nr_longitudeTextBox.Text & ");", True)
    End Sub
End Class
4

1 回答 1

2

testando第一个参数是图像 url,你没有提供它。

看来你想打电话fonte而不是testando在你的RegisterStartupScript. 也就是以经纬度为参数的方法。

编辑

改变

var src = "http://maps.google.com/maps/api/staticmap?center=lat,lon&zoom=8&size=540x280&ma‌​ptype=roadmap&sensor=false"
testando("http://maps.google.com/maps/api/staticmap?center=lat,lon&zoom=8&size=540x280&maptype=roadmap&sensor=false", 540, 280, "Mapa");

经过

var src = "http://maps.google.com/maps/api/staticmap?center=" + lat + "," + lon + "&zoom=8&size=540x280&ma‌​ptype=roadmap&sensor=false";
testando(src, 540, 280, "Mapa");

修复了两件事:

1)您没有使用latlon作为地图网址的参数,因此固定src建筑

2)添加src为参数,testeando因为您没有使用它

于 2013-05-14T14:45:59.730 回答