alhamd says:
<
script
type
=
"text/javascript"
src
=
"http://maps.googleapis.com/maps/api/js?sensor=false"
></
script
>
Change http with https.
Refer below sample.
HTML
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=API_Key"></script>
<asp:TextBox ID="txtLocation" runat="server" Text=""></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="FindCoordinates" />
<br />
<br />
<asp:Panel ID="pnlScripts" runat="server" Visible="false">
<div id="dvMap" style="width: 300px; height: 300px">
</div>
<script type="text/javascript">
var markers = [
<asp:Repeater ID="rptMarkers" runat="server">
<ItemTemplate>
{
"title": '<%# Eval("Address") %>',
"lat": '<%# Eval("Latitude") %>',
"lng": '<%# Eval("Longitude") %>',
"description": '<%# Eval("Address") %>'
}
</ItemTemplate>
<SeparatorTemplate>
,
</SeparatorTemplate>
</asp:Repeater>
];
</script>
<script type="text/javascript">
window.onload = function () {
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>
</asp:Panel>
Namespaces
C#
using System.Data;
using System.IO;
using System.Net;
using System.Text;
VB.Net
Imports System.Data
Imports System.IO
Imports System.Net
Imports System.Text
Code
C#
protected void FindCoordinates(object sender, EventArgs e)
{
string url = "https://maps.google.com/maps/api/geocode/xml?address=" + txtLocation.Text + "&key=API_Key";
WebRequest request = WebRequest.Create(url);
using (WebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
DataSet dsResult = new DataSet();
dsResult.ReadXml(reader);
DataTable dtCoordinates = new DataTable();
dtCoordinates.Columns.AddRange(new DataColumn[4] { new DataColumn("Id", typeof(int)),
new DataColumn("Address", typeof(string)),
new DataColumn("Latitude",typeof(string)),
new DataColumn("Longitude",typeof(string)) });
foreach (DataRow row in dsResult.Tables["result"].Rows)
{
string geometry_id = dsResult.Tables["geometry"].Select("result_id = " + row["result_id"].ToString())[0]["geometry_id"].ToString();
DataRow location = dsResult.Tables["location"].Select("geometry_id = " + geometry_id)[0];
dtCoordinates.Rows.Add(row["result_id"], row["formatted_address"], location["lat"], location["lng"]);
}
if (dtCoordinates.Rows.Count > 0)
{
pnlScripts.Visible = true;
rptMarkers.DataSource = dtCoordinates;
rptMarkers.DataBind();
}
}
}
}
VB.Net
Protected Sub FindCoordinates(ByVal sender As Object, ByVal e As EventArgs)
Dim url As String = "https://maps.google.com/maps/api/geocode/xml?address=" & txtLocation.Text & "&key=API_Key"
Dim request As WebRequest = WebRequest.Create(url)
Using response As WebResponse = CType(request.GetResponse(), HttpWebResponse)
Using reader As StreamReader = New StreamReader(response.GetResponseStream(), Encoding.UTF8)
Dim dsResult As DataSet = New DataSet()
dsResult.ReadXml(reader)
Dim dtCoordinates As DataTable = New DataTable()
dtCoordinates.Columns.AddRange(New DataColumn(3) {
New DataColumn("Id", GetType(Integer)),
New DataColumn("Address", GetType(String)),
New DataColumn("Latitude", GetType(String)),
New DataColumn("Longitude", GetType(String))})
For Each row As DataRow In dsResult.Tables("result").Rows
Dim geometry_id As String = dsResult.Tables("geometry").[Select]("result_id = " & row("result_id").ToString())(0)("geometry_id").ToString()
Dim location As DataRow = dsResult.Tables("location").[Select]("geometry_id = " & geometry_id)(0)
dtCoordinates.Rows.Add(row("result_id"), row("formatted_address"), location("lat"), location("lng"))
Next
If dtCoordinates.Rows.Count > 0 Then
pnlScripts.Visible = True
rptMarkers.DataSource = dtCoordinates
rptMarkers.DataBind()
End If
End Using
End Using
End Sub
Screenshot