Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
google map based on visitor information asp.net
07-15-2011, 07:15 PM
Post: #1
google map based on visitor information asp.net
i have modified my previous post Google Map in asp.net which mark the area on google map based on user address.

but this thread demonstrate how to mark the area of the visitor based on latitude and longitude values.

below is the code for marking area on google map.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Subgurim.Controles;
using System.Xml;
using System.Net;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        DataTable dt = GetGeoLocation(IpAddress());
        googleMap(Convert.ToDouble(dt.Rows[0][8]), Convert.ToDouble(dt.Rows[0][9]));

    public string IpAddress()
        string strIpAddress;
        strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (strIpAddress == null)
            strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
        return strIpAddress;

    private DataTable GetGeoLocation(string ipaddress)
        //Create a WebRequest
        WebRequest rssReq = WebRequest.Create("http://freegeoip.appspot.com/xml/"
        + ipaddress);
        //Create a Proxy
        WebProxy px = new WebProxy("http://freegeoip.appspot.com/xml/" + ipaddress, true);

        //Assign the proxy to the WebRequest
        rssReq.Proxy = px;

        //Set the timeout in Seconds for the WebRequest
        rssReq.Timeout = 2000;
        { //Get the WebResponse
            WebResponse rep = rssReq.GetResponse();

            //Read the Response in a XMLTextReader
            XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());

            //Create a new DataSet
            DataSet ds = new DataSet();

            //Read the Response into the DataSet
            return ds.Tables[0];
            return null;

    void googleMap(double lat,double lng)
        Subgurim.Controles.GeoCode GeoCode = new GeoCode();
        Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(lat, lng);
        GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
        Subgurim.Controles.GMarker oMarker = new Subgurim.Controles.GMarker(gLatLng);

please check the attachment for working example.

you can explore the google api more for different map views and to implement zoom in/out functionality.

Attached File(s)
.zip  googlemap.zip (Size: 162.13 KB / Downloads: 41)

[Image: 2604595733.png]

Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Why can I save the error information into the table of SQL server ? dongtrien 0 936 09-29-2015 04:36 AM
Last Post: dongtrien
  Google Language (translation) APIs asp.net c# nisar87 12 29,871 03-05-2015 10:45 AM
Last Post: Tariqq great
  Get DataTable Rows based on specific range linq c# nisar87 1 4,864 01-24-2013 01:03 PM
Last Post: praveen
  IP to location + google map in asp.net nisar87 4 9,124 07-19-2011 06:43 AM
Last Post: nisar87
  Google Map in asp.net nisar87 7 9,092 07-16-2011 10:41 AM
Last Post: johnpaulmathew

User(s) browsing this thread: 1 Guest(s)