but i cant get that value on Double latitude,Double Longitude
Double latitude = Convert.ToDouble(lat.Value);
Double longitude = Convert.ToDouble(lng.Value);
This is the page full
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script src="//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places&key=AIzaSyBuPeoxlUbkNOl6IyUfnqx65cMfof7gcqo" async="" defer="defer" type="text/javascript"></script>
<script type="text/javascript">
var long = 0;
var lat = 0;
window.onload = function () {
var mapOptions = {
center: new google.maps.LatLng(21.0000, 78.0000),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
//Attach click event handler to the map.
google.maps.event.addListener(map, 'click', function (e) {
//Determine the location where the user has clicked.
var location = e.latLng;
//Create a marker and placed it on the map.
var marker = new google.maps.Marker({
position: location,
map: map
});
//Attach click event handler to the marker.
google.maps.event.addListener(marker, "click", function (e) {
var infoWindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br />Longitude: ' + location.lng()
});
infoWindow.open(map, marker);
});
google.maps.event.addListener(map, 'click', function (e) {
long = e.latLng.lng();
lat = e.latLng.lat();
document.getElementById("lat").value = lat;
document.getElementById("lng").value = long;
document.getElementById("<%=lat.ClientID%>").value = lat;
document.getElementById("<%=lng.ClientID%>").value = long;
alert("Latitude: " + lat + "\r\nLongitude: " + long);
});
});
};
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:HiddenField ID="lat" runat="server" />
<asp:HiddenField ID="lng" runat="server" />
<div id="dvMap" style="width: 500px; height: 500px">
</div>
<asp:Button ID="btn" runat="server" Text="go" OnClick="btn_Click" />
</asp:Content>
This is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
Double latitude = Convert.ToDouble(lat.Value);
Double longitude = Convert.ToDouble(lng.Value);
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=F:\shafeek\aspprojects\WebSite1\App_Data\Database.mdf;Integrated Security=True";
string query1 = "insert into Courses(longi,lati) values (@lati, @longi)";
SqlCommand cmd1 = new SqlCommand(query1, con);
cmd1.Parameters.AddWithValue("@lati", latitude);
cmd1.Parameters.AddWithValue("@longi", longitude);
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
}
}