Showing posts with label google map. Show all posts
Showing posts with label google map. Show all posts

Saturday, April 28, 2012

C# Function to get Geo Coding Using Google Maps Geocoding API


 using  Newtonsoft.Json;
 


    public class GeoLocation
    {
        public decimal Lat { getset; }
 
        public decimal Lng { getset; }
    }
 
    public class GeoGeometry
    {
        public GeoLocation Location { getset; }
    }
 
    public class GeoResult
    {
        public GeoGeometry Geometry { getset; }
    }
 
    public class GeoResponse
    {
        public string Status { getset; }
 
        public GeoResult[] Results { getset; }
    }


private Dictionary<stringstring> getLatLong(string address)
    {
  Dictionary<stringstring> diclatlong = new Dictionary<stringstring>();
  string url = "http://maps.googleapis.com/maps/api/geocode/json?address=" 
                + Server.UrlEncode( address) + "&sensor=false";
        WebResponse response = null;
        try
        {
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
         request.Method = "GET";
         response = request.GetResponse();
         if (response != null)
         {
           string str = null;
           using (Stream stream = response.GetResponseStream())
           {
            using (StreamReader streamReader = new StreamReader(stream))
            {
             str = streamReader.ReadToEnd();
            }
           }
            GeoResponse geoResponse = JsonConvert.DeserializeObject<GeoResponse>(str);
            if (geoResponse.Status == "OK")
            {
             int count = geoResponse.Results.Length;
             for (int i = 0; i < count; i++)
             {
        diclatlong.Add("Lat", geoResponse.Results[i].Geometry.Location.Lat.ToString());
        diclatlong.Add("Lng", geoResponse.Results[i].Geometry.Location.Lng.ToString());
             }
            }
            else
             {
              diclatlong.Add("Lat""");
              diclatlong.Add("Lng""");
             }
            }
        }
        catch
        { throw new Exception ("JSON response failed."); }
        finally
        {
            if (response != null)
                {
                response.Close ();
                response = null;
                }
        }
        return diclatlong;
    }


I have used JSon.NET Library

Saturday, July 28, 2007

Meteor Crater's of the World

Find the Craters formed by the Meteor Impact's around the world on Google map here

Monday, June 11, 2007

My blog is powered with Google Map

Hi Recently i have added google map feature to my blog you can zoom using scroll mouse,u can drag and see other parts of the world.

Adding Google Maps to your site

With Google Map API its easier to add maps to web sites. Recently i was working on it and found it very simple and easy to add. Following steps will help you to add maps.

Step 1. : Register with Google(http://www.google.com/apis/maps/signup.html) to Get a Key.
Step 2. : Add the following script in Head tag of the HTML Page

<script
src="http://maps.google.com/maps?file=api&v=2.x&key=ABC" type="text/javascript">


Step 3.: Add a div tag as shown below inside body tag

<div id="map" style="width: 400px; height: 500px;"></div>
(this div will display the map)
Step4.: Add the following code to your body tag

<script type="text/javascript">
var map = new GMap2(document.getElementById("map"));
map.enableScrollWheelZoom();
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(12.9484,77.5688), 16,null);
var marker = new GMarker(new GLatLng(12.9484,77.5688);
map.addOverlay(marker);
marker.openInfoWindowHtml("Just bouncing along...");

</script>

Step5.: Add latitude and longitude of the place in above code(replace the bold numbers with your lat long)


Latitude and Longitudes must be in Decimal Digits(DD) format instead of Degree Minute Second(DMS) Format.

You can get Latitude and Longitudes in DD format from Earth Tools.