Google Anlatics

Tuesday, August 23, 2011

Google Map API V3 with ASP .Net


Google Map API V3 with ASP .Net 4.0

This is the link for Google Map API Version 3


Google Geocoding API no longer requires a Maps API key!
Google Maps API Premier customers must additionally sign their URLs using a new cryptographic key. See the Premier documentation for more information.

For premium usage
is the link and by filing above link can buy the

Google API Map premium account.

Usage Limits

Use of the Google Geo coding API is subject to a query limit of 2,500 geo location requests per day. (User of Google Maps API Premier may perform up to 100,000 requests per day.) This limit is enforced to prevent abuse and/or repurposing of the Geo coding API, and this limit may be changed in the future without notice. Additionally, we enforce a request rate limit to prevent abuse of the service. If you exceed the 24-hour limit or otherwise abuse the service, the Geo coding API may stop working for you temporarily. If you continue to exceed this limit, your access to the Geo coding API may be blocked.
Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions.

For XML version normal user

For XML version Premier user

gme-myclientID is Google premier ID

If the client id is not valid then following error message will displayed
Unable to authenticate the supplied URL. Please check your client and signature parameters.

Some coding examples with C# .NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Xml;

namespace WebApp
{
    public class GeoCode
    {
        protected const string googleClientID = "googleClientID";
        public interface IGeoLocation
        {
            double latitude { get; set; }
            double longitude { get; set; }
            string geocodeurl { get; set; }
        }

        public struct GeoLocation : IGeoLocation
        {
            private double _latitude;
            private double _longitude;
            private string _geocodeurl;

            public GeoLocation(double latitude, double longitude, string geocodeurl)
            {
                _latitude = latitude;
                _longitude = longitude;
                _geocodeurl = geocodeurl;
            }

            public double latitude
            {
                get { return _latitude; }
                set { _latitude = value; }
            }

            public double longitude
            {
                get { return _longitude; }
                set { _longitude = value; }
            }

            public string geocodeurl
            {
                get { return _geocodeurl; }
                set { _geocodeurl = value; }
            }
        }
      
 public class GeoCode
 {
    const string _googleUri = "http://maps.googleapis.com/maps/api/geocode/xml?address=";

    private static Uri GetGeoCodeURI(string address)
    {
        address = HttpUtility.UrlEncode(address);
   

        string _googleJsapiUrl = System.Configuration.ConfigurationManager.AppSettings[googleClientID];

        string uri = String.Format("{0}{1}&client={2}&sensor=false", _googleUri, address, _googleJsapiUrl);               

                return new Uri(uri);
            }

            public static GeoLocation GetCoordinates(string address)
            {
                WebClient wc = new WebClient();
                Uri uri = GetGeoCodeURI(address);

                try
                {
                    string geoCodeInfo = wc.DownloadString(uri);
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(geoCodeInfo);

                    string status = xmlDoc.DocumentElement.SelectSingleNode("status").InnerText;
                    double geolat = 0.0;
                    double geolong = 0.0;
                    XmlNodeList nodeCol = xmlDoc.DocumentElement.SelectNodes("result");
                    foreach (XmlNode node in nodeCol)
                    {
                        geolat = Convert.ToDouble(node.SelectSingleNode("geometry/location/lat").InnerText, System.Globalization.CultureInfo.InvariantCulture);
                        geolong = Convert.ToDouble(node.SelectSingleNode("geometry/location/lng").InnerText, System.Globalization.CultureInfo.InvariantCulture);
                    }
                    return new GeoLocation(geolat, geolong, uri.ToString());
                }
                catch
                {
                    return new GeoLocation(0.0, 0.0, "http://");
                }
            }
        }
    }
}

Creating object of Geo Code and passing address attribute will generate out form XML Version.

GeoCode.GeoLocation geolocation = GeoCode.GeoCode.GetCoordinates("1128 West Hastings Street " + ","+ "Vancouver" + "," + " British" + "," + "Columbia" + "canada");

JSon also support like XML for premier user.

No comments:

Sri Lanka .NET 
                Forum Member