Click here to Skip to main content
16,016,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I want to use google map in my website.

I have 4 locations and I want to go to each location when link button for corresponding location is clicked.

Here is the code I am using

ASP.NET
<script type="text/javascript">
    function init_map() {
        var myOptions = {
            zoom: 6, center: new google.maps.LatLng(40.805478, -73.96522499999998), mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
        marker = new google.maps.Marker({ map: map, position: new google.maps.LatLng(40.805478, -73.96522499999998) });
        infowindow = new google.maps.InfoWindow({ content: "india<br/>2880 Broadway<br/> New York" });
        google.maps.event.addListener(marker, "click", function () { infowindow.open(map, marker); });
        infowindow.open(map, marker);
    }
    google.maps.event.addDomListener(window, 'load', init_map);

    function Goto(lat, long) {
        debugger;
        var myOptions = {
            zoom: 6, center: new google.maps.LatLng(lat, long), mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
        marker = new google.maps.Marker({ map: map, position: new google.maps.LatLng(40.805478, -73.96522499999998) });
        infowindow = new google.maps.InfoWindow({ content: "<br/>2880 Broadway<br/> New York" });
        google.maps.event.addListener(marker, "click", function () { infowindow.open(map, marker); });
        infowindow.open(map, marker);
    }

</script>

body>
        <form runat="server">
            <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="Goto(33.7018259,-117.85699)">1231 East Dyer Road</asp:LinkButton>
            <asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="Goto(40.764847,-73.9782006)">123 West 57th Street</asp:LinkButton>
            <asp:LinkButton ID="LinkButton3" runat="server" OnClientClick="Goto(22.3009512,114.172173)">Unit 1603, 16/F Miramar Tower</asp:LinkButton>
            <asp:LinkButton ID="LinkButton4" runat="server" OnClientClick="Goto(48.8567,2.3508)">36-38 rue des Mathurins</asp:LinkButton>
        </form>
    </body>


What I am getting is whenever I click the link button it is not navigating to the location. Can you please help me.?


Thanks,
In advance
Posted

1 solution

Don't use LinkButton unless you need the link to do a postback, use a normal link instead

<a href="#" onclick="Goto(33.7018259,-117.85699); return false;">1231 East Dyer Road</a>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900