locked
Google Map Parameter RRS feed

All replies

  • User-1174608757 posted

    Hi powderworks,

    According to your description,I have made a sample here. It seems that you want to pass parameters to the src of scripts from code behind. I suggest that  you could define an string object in code behind and then use <%=stringname%> in the front end ,so that you could  get it.

    Here is a demo I hope it could help you.

    google.aspx:

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <script src='<%=this.sql %>'></script>
            </div>
        </form>
    </body>
    </html>
    

    aspx.cs:

        public partial class google : System.Web.UI.Page
        {
            public string sql { get; set; }
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string Town = "town";
                    string state = "state";
    //use string.format to set the content of sql sql = string.Format("https://maps.googleapis.com/maps/api/staticmap?center={0},{1}&zoom=14&size=400x400&key=", Town, state); } } }

    Best Regards

    Wei

    Wednesday, June 12, 2019 2:37 AM
  • User336760158 posted

    Thanks for coming back to me. I tried put your suggestion for string.Format into my Code but it is not working shows blank imagine . Source code showing not picking up Town2 and State2

    String GoogleMap = "";
    String Town2 = TownT.Text;
    String State2 = StateT.Text;
    GoogleMap = String.Format("https://maps.googleapis.com/maps/api/staticmap?center={0},{1}&zoom=14&size=400x400&key=AIzaSyA5saA40eBRjjspqjtZSIZoqas3sBWrrCo", Town2, State2);
    A3picture.ImageUrl = GoogleMap;

    Update: We are not getting any data from TextBoxs . need to investigate

    Thursday, June 13, 2019 12:12 AM
  • User-1174608757 posted

    Hi powderworks

    I have tried your code here.There is no problem to insert Town2 and State2 into the string.You could see as below:

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    String GoogleMap = "";
                    String Town2 = "aaa";
                    String State2 = "bbbb";
                    GoogleMap = String.Format("https://maps.googleapis.com/maps/api/staticmap?center={0},{1}&zoom=14&size=400x400&key=AIzaSyA5saA40eBRjjspqjtZSIZoqas3sBWrrCo", Town2, State2);
                    Response.Write(GoogleMap);
                }
    
            }
         

    You could see:

    So I think string Town2 and State2 is empty so that GoogleMap source is not right.I hope that you could host you codes both in front end and code behind.It will help us to solve your problem.

    Best Regards

    Wei

    Thursday, June 13, 2019 1:42 AM
  • User336760158 posted

    Thanks you are correct. So I need to find data problem

    Thursday, June 13, 2019 1:44 AM