简体   繁体   中英

setting marker for given address in google maps api with asp.net

I am doing a web application using asp.net in which I want to take an address from a user in a textBox and show this address in a google maps api (that I implemented in my web application) by a marker (the tear drop shaped thing). So can someone please give me the code for doing that?

If you are looking for placing a marker on the map by taking an address, then you need to look at the Geocoding service first. The example and description is well documented so I am not providing any code related to it.

GEOCODING SERVICE

The example provided above will take input from a HTML input element. Since your question is about taking input from an Asp.net TextBox this is what you can do-

Suppose you have-

<asp:TextBox ID="txt_address" runat="server"> 
<asp:Button ID="btn_locate" runat="server" OnClientClick="codeAddress(); return false;">

instead of var address = document.getElementById("address").value; in the example,

write-

var address= document.getElementById('<%=txt_address.ClientID%>').value;

Remember the return false in the Button source since that will prevent a postback on submit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM