Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

Google Maps Control for ASP

VIEWS: 3,886 PAGES: 78

									Google Maps Control for ASP.Net - Part 1
Sunday, 23 November 2008 16:52 Shabdar


Free Open source Control
  Download source - 115kb

Version 1.5

Following changes are done in this version.

      In previous versions javascript functions were embedded in
       GoogleMapForASPNet.ascx source. In this version javascript functions
       are separated in GoogleMapAPIWrapper.js file. This is done so that
       javascript source can be cached locally on client machine.
      Now you can change shadow image of a marker. Following new
       properties are added.
       IconShadowImage - Defines which image should be used for shadow.
       Image path should be given relative to root folder.

            GP1.IconImage = "icons/pushpin-blue.png";
           GP1.IconShadowImage = "icons/pushpin-blue-shadow.png";

       IconShadowWidth - shadow width
       IconShadowHeight - shadow height

       Usually you don't need to provide IconShadowWidth and
       IconShadowHeight property values because this control tries to find height
       and width of image automatically.

      Icon and InfoWindow Anchor properties are now supported.
       IconAnchor_posX - This defines Icons anchor position from left.
       IconAnchor_posY - This defines Icons anchor position from top.

       InfoWindowAnchor_posX - This defines Info Window(balloon)'s anchor
       position from left.
       InfoWindowAnchor_posY - This defines Info Window(balloon)'s anchor
       position from top.

       For more information on Anchors, visit following article.
       Making your own custom markers

      Source Code documentation for this control is released alongwith
       this version. Click on following link to view this documentation,
       Google Maps Control for ASP.Net - Part 2

Version 1.4

Following changes are done in this version.

      Geocoding is now supported in this version. You can find Latitude and
       Longitude value based on an Address. Here is how to do it
         GooglePoint GP = new GooglePoint();
         GP.Address = txtAddress.Text;
        //GeocodeAddress() function will geocode address and set Latitude and Longitude of GP(GooglePoint) to it's
    respected value.
         if (GP.GeocodeAddress(txtAPIKey.Text))
         {
             //Get Latitude value in a variable
             double Latitude = GP.Latitude;
             //Get Longitude value in a variable
             double Longitude = GP.Longitude;
             GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP);
         }
         else
         {
             lblError.Text = "Unable to geocode this address.";
         }


    Download source and see samples for detailed implementation.

   Automatic boundary is now set by default. i.e.,if pushpins are moving
    continuously on map and they go outside map boundaries, map will reset
    it's bounds to accomodate pushpins.
    You can disable automatic boundaries using following code.

    GoogleMapForASPNet1.GoogleMapObject.AutomaticBoundaryAndZoom =
    false;

   Now you can recenter map to a new position. This was a bug in previous
    versions. See sample code below for new implementation,

    protected void btnRecenter_Click(object sender, EventArgs e)
        {
                GooglePoint GP = new GooglePoint();
                GP.Latitude = 43.66619;
                GP.Longitude = -79.44268;
                GP.InfoHTML = "This is a new center point";
                GoogleMapForASPNet1.GoogleMapObject.CenterPoint = GP;
                GoogleMapForASPNet1.GoogleMapObject.RecenterMap =
    true;
        }


   A bug related to Visual Studio 2008 is fixed. Old version was getting stuck
    in design view. This version should work fine.
   control in GoogleMapControl.ascx is replaced with control. This allows
    users to place control on web page itself and thus allowing them to use
    Ajax controls before Google Map Control.
   A small bug related to Satellite or Hybrid View is fixed. You can set
    Satellite View programatically as below,

            GoogleMapForASPNet1.GoogleMapObject.MapType =
    GoogleMapType.SATELLITE_MAP;

                                                            or
     GoogleMapForASPNet1.GoogleMapObject.MapType =
    GoogleMapType.HYBRID_MAP;

                                       or

     GoogleMapForASPNet1.GoogleMapObject.MapType =
    GoogleMapType.NORMAL_MAP;

    Version 1.3

    Following changes are done in this version.

   Added a new property called RecenterMap. When it's set to true map will
    be re-centered and zoomed to default level on postback.
   Now you can add Tooltip for markers.




   Draggable pushpins are now supported.
Version 1.2

Following changes are done in this version.

      A minor bug related to Polygons is fixed
      Now you can enable or disable Traffic overlays.




Version 1.1

Following features are added in this version.

      Now you can draw polylines and polygons with this control
   
      A new property GoogleMapObject.APIVersion is added with this control.
       This will allow users to use any version of Google Maps API. Default
       version is 2.

Introduction

Most of us are familiar with google map. Google has provided a very reach APIs
to use it in our own application. But we need some short of javascript knowledge
in order to use it. I don't know about others, but for me it was a little difficult to
use javascript along with google apis in ASP.Net pages, specifically if you want
to use server side functions to draw google map dynamically. For example, in my
case I wanted to pull latitude longitude information from a SQL Server database
and then use them to insert pushpins on google map. If you are familiar with Ajax
framework, you know the answer. You will have to call asp.net server side
function from javascript and use retrieved data to draw a google map. How
simple is that? :). Atleast not for me. So I have decided to write a user control
which can take care of javascript part and allows me to concentrate on
serverside functions.

Features
Enables you to draw google map. No javascript knowledge required. Just drag
and drop control on your page.

      Uses Ajax calls to retrieve server side data.
      Enables you to change pushpin postions on the fly. No need to refresh full
       map.
      Enables you to change pushpin icons on the fly.
      Optimized to give you best performance. i.e., only those pushpin data will
       be retrieved from server that are changed.

How to use

In this part of article, I don't want you to explain how I created this control.
Instead I want you to start using it. To view documentation for source code visit
following article.
Google Maps Control for ASP.Net - Part 2

Requirements

      Visual Studio 2005 or higher
      Microsot ASP.Net Ajax framework. You can download it from here.
      Internet Explorer 7.0 or Mozilla Firefox 2.x.
       (Note: It may work on other browsers. I have tested on IE and Firefox
       only.)

Follow below steps in order to use it in your ASP.Net website.

      Download source from link provided on top of the page. Extract it
       somewhere on your harddrive.
      Open extracted folder as a website in Visual Studio and run it. When you
       run this website, you will be able to navigate few samples pages.
      To use this control in your application, copy following files to your ASP.Net
       application in same structure as shown below.
Now we will add reference to Ajax library. If you are already using Ajax controls
in your application, you can skip following 4 steps.

Adding Ajax Framework to your website

      Right click on your website in solution explorer and click add reference.




      In Add Reference window, select System.Web and
       System.Web.Extensions libraries and click OK. Note library versions (in
       below picture 1.0.61025.0. You may have another version. You can use
       any version).
     Go to your web.config file and add following lines between element.

        type="System.Web.Script.Services.ScriptHandlerFactory,
        System.Web.Extensions, Version=1.0.61025.0,
        Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"
        validate="false"/>

        type="System.Web.Script.Services.ScriptHandlerFactory,
        System.Web.Extensions, Version=1.0.61025.0,
        Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"
        validate="false"/>

        type="System.Web.Handlers.ScriptResourceHandler,
        System.Web.Extensions, Version=1.0.61025.0,
        Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"
        validate="false"/>

        type="System.Web.Handlers.ScriptModule,
        System.Web.Extensions,
        Version=1.0.61025.0, Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"/>



      Note : Make sure that version of System.Web.Extension library is same
      as what you have selected when you added reference.

Adding Google Map control to your webpage

     Open page where you want to insert Google Map.
      Drag GoogleMapForASPNet.ascx control to your page.




       You won't be able to see Google Map in design view. Instead, you should
       see Script Manager as part of this control.
      At this point you can run your application and you should be able to see a
       blank Google Map on your page as shown below.




Let's add few pushpins on this map. For that you will have to add some code in
Page_Load() event of your page.
Passing parameters to Google Map control

     You must specify Google Map API Key for this component. You can obtain
      this key from http://code.google.com/apis/maps/signup.html.

      if (!IsPostBack)
      {
        GoogleMapForASPNet1.GoogleMapObject.APIKey = "";

      Note that inialization code for map should go inside if (!IsPostBack)
      block.

     Optionally you can specify which version of Google maps API to use. You
      can get more information about Google Maps API version here.

      GoogleMapForASPNet1.GoogleMapObject.APIVersion = "2";

     Specify width and height for map. You can specify either in pixels or in
      percentage relative to it's container.

       GoogleMapForASPNet1.GoogleMapObject.Width = "800px";
       GoogleMapForASPNet1.GoogleMapObject.Height = "600px";

     Specify zoom level. Default is 3.

       GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 14;

     Specify Center Point for map. Map will be centered on this point.

      GoogleMapForASPNet1.GoogleMapObject.CenterPoint
          = new GooglePoint("CenterPoint", 43.66619, -79.44268);

     Add pushpins for map. This can be done by initializing GooglePoint type
      object. In constructor of GooglePoint, First argument is ID of this pushpin.
      It must be unique for each pin. Second and third arguments are latitude
      and longitude.

      GoogleMapForASPNet1.GoogleMapObject.Points.Add(
      new GooglePoint("1", 43.65669, -79.45278));

      Alternatively you can also do it like below,

      GooglePoint GP = new GooglePoint();
      GP.ID = "1";
      GP.Latitude = 43.65669;
      GP.Longitude = -79.43270;
      GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP);
      You can add as many pushpins as you wish. Now run website again and
      you should see pushpins on map.




Assigning custom icon to pushpins

     You can assign your own icons with google map control. For that first copy
      your icons in some directory under root directory of your website. You can
      assign icon to a pushpin as below,

      GP.IconImage = "icons/pushpin-blue.png";

      Note that path to image is relative to root folder. You should have icons (or
      whichever) directory in root folder of your website.

     You can add description of a pushpin which will pop up when user clicks a
      pushpin.

      GP.InfoHTML = "This is Pushpin-1";
      You can format InfoHTML property using standard HTML tags.
       example,

       GP.InfoHTML = "This is Pushpin-1";




   




Up to this point, I have explained you basics of using Google Map control. Now
let's implement some advanced functionality. Let's say we want to move
pushpins when user do some action. For example when a user clicks on a
button. For that, follow below steps.

Creating Interactive Map

You can create interactive map using Google Map control. You can move
pushpins when user clicks on a button. Here is how you can do it.

      Insert standard asp.net button on your web page. Write following code in
       click event of this button.

       protected void Button1_Click(object sender, EventArgs e)
       {
          GoogleMapForASPNet1.GoogleMapObject.Points["1"].Latitude +=
       0.003;
          GoogleMapForASPNet1.GoogleMapObject.Points["1"].Longitude +=
       0.003;
       }

       We are incrementing Latitude and Longitude value for Pushpin-1 here.
       Note that I am using ID(In above code "1") of pushpin to set new Latitude
       and Longitude.

      Run your application and click on Button. You will note that whole page
       get's refreshed (or postback). To stop it from posting back, you need to
       wrap this button with an Ajax Update panel. Go to Visual Studio toolbox
       and drag Ajax Updatepanel control on your page.




      Move your button inside this update panel.




      Now run website again and click on button. You should notice that now
       page is not posting back and Pushpin moves on map.



Auto refreshing map and GPS Navigation

You can use Ajax Framewor's timer control in similar way as button control (I
have explained above). On Timer_Tick() event you can specify new latitude
longitude for all pushpins. This way Map will move all pushpins automatically
after specified time delay. You can hook up any GPS service with this control to
create GPS Navigation system.

Creating Polylines with Google Map control
   Create points for polyline,

    //Define Points for polygon
    GooglePoint GP1 = new GooglePoint();
    GP1.ID = "GP1";
    GP1.Latitude = 43.66675;
    GP1.Longitude = -79.4042;

    GooglePoint GP2 = new GooglePoint();
    GP2.ID = "GP2";
    GP2.Latitude = 43.67072;
    GP2.Longitude = -79.38677;
    .
    .//Define GP3,GP4,GP5,GP6 and GP7 in similar way
    .
    GooglePoint GP7 = new GooglePoint();
    GP7.ID = "GP7";
    GP7.Latitude = 43.66656;
    GP7.Longitude = -79.40445;

   Create polyline between points GP1, GP2 and GP3

    //Create Polygon using above points
    GooglePolygon PG1 = new GooglePolygon();
    PG1.ID = "PG1";
    //Give Hex code for line color
    PG1.FillColor = "#0000FF";
    PG1.FillOpacity = 0.4;
    //Stroke is outer border of polygon.
    PG1.StrokeColor = "#0000FF";
    PG1.StrokeOpacity = 1;
    PG1.StrokeWeight = 2;
         //Add points to polygon
         PG1.Points.Add(GP1);
         PG1.Points.Add(GP2);
         PG1.Points.Add(GP3);
         PG1.Points.Add(GP4);
         PG1.Points.Add(GP5);
         PG1.Points.Add(GP6);
         PG1.Points.Add(GP7);

        Add Polyline to Google Map control,

         GoogleMapForASPNet1.GoogleMapObject.Polygons.Add(PG1);

Traffic Overlays

        To enable or disable traffic overlay, set following property to true or false,

         GoogleMapForASPNet1.GoogleMapObject.ShowTraffic = true;

         Note: Traffic overlays may not be available in every region. To get more
         information on traffic overlays visit below link,
         http://code.google.com/apis/maps/documentation/services.html#Traffic_O
         verlays

Go through samples provided in download. I have explained all sort of
circumtances in which you may want to use google map control. If you have any
questions, feel free to ask.

In Part 2, I have explained souce code of Google Map user control and how to
customize it for your own use.
Google Maps Control for ASP.Net - Part 2

Special Notes

I have published this article on www.codeproject.com as well. Here is the link to
this article.

Google Maps Control for ASP.Net - Part 1



Comments/Questions


Hi

A couple of questions
Are you planning to add support for loading KMLs via the control?

Are you planning to add the ability to overlay more recent aerial photos onto Google Maps via
the control?

Thanks

Tim
=> TimM (Monday 24-Mar-08 10:29 PM)
Yes I am trying to include all functionalities that current Google APIs provide. But I can not
tell you when.
=> Shabdar (Tuesday 25-Mar-08 11:42 AM)



Thanks for your Google maps control!
But I have one problem. I my site I would like that site-user may put pushpins on maps. May I
do this with your control or I have to write some code?
=> Vlad (Tuesday 25-Mar-08 12:53 PM)

Yes it is possible to add more pushpins. Sample code :
GoogleMapForASPNet1.GoogleMapObject.Points.Add(new GooglePoint("NewPin1",
43.23334, -78.44322)); But right now this control does not support draggable markers.I will
release a new version soon.
=> Shabdar (Tuesday 25-Mar-08 01:24 PM)



Hi

if i set the height/width to a percentage... it doesnt show the map correctly.. only the map
controls.

im trying to set it to 100percent of its parent div.

thanks

J
=> JG (Tuesday 25-Mar-08 02:29 PM)

This is not a control problem. This is a general problem with any control. You can solve it in
three ways.
(1)Remove this line in your aspx page source ->
(2) Or go to GoogleMapForASPNet.ascx source and change
to
(3)Set control container (DIV) to fixed width and height. Then apply percentage width and
height to control.
=> Shabdar (Tuesday 25-Mar-08 03:31 PM)



I am having a slight problem with GoogleMapObject.CenterPoint when the button is in an
update panel.

GoogleMapObject.CenterPoint works ok on page load... and pins are created ok by the button
in the updatepanel... but not the maps center location.

any ideas?
=> JG (Tuesday 25-Mar-08 05:52 PM)

Thanks Jonny for reporting this. This is a small bug. I will release a new version in a day or
two. For now you can fix it as below.

Go to GoogleMapForASPNet.ascx page source code. Add following line at the start of
javascript function *fGetGoogleObjectOptimized*

function fGetGoogleObjectOptimized(result, userContext)
{
map.setCenter(new GLatLng(result.CenterPoint.Latitude, result.CenterPoint.Longitude),
result.ZoomLevel);
.
.//Keep rest of the code as it is
.
}
=> Shabdar (Thursday 27-Mar-08 11:24 AM)

   As per your guide i place the function fGetGoogleObjectOptimized(result, userContext)
   {
   map.setCenter(new GLatLng(result.CenterPoint.Latitude, result.CenterPoint.Longitude),
   result.ZoomLevel);
   .
   .//Keep rest of the code as it is
   .
   } this function to .ascx page but not placing updated(new) point as center. I need to
   manually drag the map to get that point.
   => sridhar (Wednesday 16-Apr-08 09:35 AM)
it works well on my local machine.. but on the web server i get a grey box and this error...

The server method 'GetGoogleObject' failed with the following error:
System.NullReferenceException...
=> JG (Wednesday 26-Mar-08 03:10 PM)

sorry - ignore that. The problem is that i have URL forwarding from my domain to the
subfolder on my web server which holds the web site... if i go directly to this folder it works
ok - ill need to sort this one out myself.

Great work by the way!!!
=> JG (Wednesday 26-Mar-08 03:26 PM)



Can any one help me in this regard?

Thank you,
-Sandeep
=> sandeep (Tuesday 07-Oct-08 04:38 AM)



Are you intending on adding any kind of spatial querying to this project. I'd like to query
whether or not a point is inside a polygon... returning true or false. Is this possible?

Cheers
Jon
=> Jon Satchwell (Thursday 27-Mar-08 04:24 AM)

Scrolling zoom enabled

Hi,
Is there any way of including the scroll wheel zoom feature in this .net version. It is now
included in the Google map API?

The javascript is:
map.enableScrollWheelZoom();

blog here:
http://googlemapsapi.blogspot.com/2007/04/v278-go-ahead-scroll-your-mouse-wheels.html

Cheers for any help!

jon
=> Jon Satchwell (Friday 28-Mar-08 08:07 AM)
Hi Jon,

Rather late response, but for the sake of others: I added the following lines to
GoogleMapForASPNet.ascx into both fGetGoogleObject and fGetGoogleObjectOptimized
methods.

// Add the Terrain map type
map.addMapType(G_PHYSICAL_MAP);

map.setMapType(eval(result.MapType));
// Add zoom via mouse double click
map.enableDoubleClickZoom();
// Add zoom via mouse scroll wheel
map.enableScrollWheelZoom();

Note this also adds Terrain map type but you need to change your Api version to "2.x:". For
example:
GoogleMapForASPNet1.GoogleMapObject.APIVersion = "2.x";
=> Chris Mangiapane (Sunday 01-Jun-08 12:59 PM)



have you any plans to add GInfoWindowTab ?
=> JG (Tuesday 01-Apr-08 05:38 AM)

Hi

GoogleMapForASPNet1.GoogleMapObject.MapType= "G_SATELLITE_MAP"

I nide to change the default map type to Satallite Map

Please help me
Great
=> Zayati (Thursday 03-Apr-08 02:39 AM)

You need to do it like this,

GoogleMapForASPNet1.GoogleMapObject.MapType=
GoogleMapType.SATELLITE_MAP;

GoogleMapType is a sealed class defined in cGoogleMap.cs file.
=> Shabdar (Thursday 03-Apr-08 01:20 PM)

     why did I put this code
      GoogleMapForASPNet1.GoogleMapObject.MapType=
      GoogleMapType.SATELLITE_MAP;

      but it always dislay type Map_Normal? :(
      => Quang (Wednesday 20-Aug-08 11:40 PM)



I'd like to use the control in my VB.Net site. So you have a VB sample? Thanks, Chad
=> Chad Hanson (Thursday 03-Apr-08 02:39 PM)




Hi!

It is a great control but there seems to be a serious bug in IE if I put it into a table. For
example:




Only a part of the map gets displayed and it is miscentered.
=> legcsabi (Sunday 06-Apr-08 04:39 AM)

      Yes, this is a known bug. Google map does not behave well with IE relative positioning.
      To overcome this you should use fix width and height. Something like this,




      => Shabdar (Monday 07-Apr-08 10:00 AM)

         Hi!
       I was unable to fix this bug using the code above. However this answer seems to be
       right: http://groups.google.com/group/Google-Maps-API/msg/261a783ea607d256

       How can we force the control to put its javascript code outside the table? (table is
       located on a separate aspx page)
       => legcsabi (Monday 14-Apr-08 01:19 AM)

          Solution:

          if (GBrowserIsCompatible())
          {
          container = document.getElementById("GoogleMap_Div");
          width = parseInt(container.style.width);
          height = parseInt(container.style.height);
          map = new GMap2(container, {size:new GSize(width,height)});
          => legcsabi (Sunday 20-Apr-08 09:05 AM)

              Hi,

              I'm facing same problem.
              Can pl. give more detail on how to debug this problem.

              Awaiting for your reply
              => Tamil (Thursday 15-May-08 02:48 AM)

                    Right now I don't have answer for moving Javascript code outsite .
                    Problem here is, this control renders Javascript code inside element
                    where it is located. So to overcome this problem, you need to get rid of
                    and try HTML tag.
                    => Shabdar (Thursday 15-May-08 09:52 AM)




In your introduction you mention that this article is to explain how to use the control and you
do a great job at explaining that. Can you write another article explaining the implementation
details?

and thank you for the great control
=> Al (Sunday 06-Apr-08 06:43 PM)

   Yes, I will be writing implementation details very soon so that you can customize it for
   your needs.
   => Shabdar (Monday 07-Apr-08 10:02 AM)

       i need good ducumantion for presentation of google map coding
       => hitesh (Wednesday 09-Apr-08 05:00 AM)



How do i get the bounds of the map?
the javascript using Google maps API was map.getBounds();

How do i add this functionality?
=> Al (Sunday 06-Apr-08 09:56 PM)

   Right now I don't have getBounds() method implemented. I will accomodate this method
   in new version.

   If you are trying to set a zoom level so that all points are in viewable area of the map,
   you can do so by appending following code at the end of fGetGoogleObject() and
   fGetGoogleObjectOptimized() javascript functions in ASCX file.

   map.setZoom(map.getBoundsZoomLevel(bounds)-1);
   map.setCenter(bounds.getCenter());
   => Shabdar (Monday 07-Apr-08 10:07 AM)



javascript function *fGetGoogleObjectOptimized*

function fGetGoogleObjectOptimized(result, userContext)
{
map.setCenter(new GLatLng(result.CenterPoint.Latitude, result.CenterPoint.Longitude),
result.ZoomLevel);
.
.//Keep rest of the code as it is
.
}

it act like hard code value every time the map center the location when it is load first time .
and same proble in zooming level.
Please tell me about the solution .thanks in advance
=> waseem (Monday 07-Apr-08 07:43 AM)

   I have resolved this issue in Version 1.3. See my release notes.
   You can stop map from zooming and recentering to a default center point by specifying
   following property

   GoogleMapForAspNet1.RecenterMap = false;

   This will prevent map from zooming to a default center point.
   => Shabdar (Monday 07-Apr-08 10:13 AM)



Thanks for response Shabdar.

I use your control in my vehicle tracking web site it run nicely.
but when vehicle move contineously and reach at the boder of the map vehicel location can
not center.
you have any idea about this problem when the vehicle reach at border the it the map is
center at latest location of the vehicle .

Thanks in advance


=> waseem (Tuesday 08-Apr-08 02:21 AM)

   Waseem,
   This is a good suggestion to move map dynamically when pushpins are not withing map
   area. I will add this feature in next release. But for now you can apply following
   solution.

   Add an Ajax Timer control on your webpage where you have inserted google map
   control. On Timer_Tick event, set center point of map to your vehicle position.

   Example,

   protected void Timer1_Tick()
   {
   GoogleMapForAspNet1.GoogleMapObject.CenterPoint =
   GoogleMapForAspNet1.Points["YourVehiclePushpinId"];
   }

   This will move map to accomodate your vehicle position. This is not the best solution,
   but use it for now.
   => Shabdar (Wednesday 09-Apr-08 09:48 AM)



hi,how to find distance between two points on map
=> Revathi (Tuesday 08-Apr-08 05:41 AM)

   Use following class to calculate distance between two geopoints. It returns distance in
   kilometers,

   using System;
   using System.Text;

   public class CDistanceBetweenLocations
   {
   public static double Calc(double Lat1,
   double Long1, double Lat2, double Long2)
   {
   /*
   The Haversine formula according to Dr. Math.
   http://mathforum.org/library/drmath/view/51879.html

   dlon = lon2 - lon1
   dlat = lat2 - lat1
   a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
   c = 2 * atan2(sqrt(a), sqrt(1-a))
   d=R*c

   Where
   * dlon is the change in longitude
   * dlat is the change in latitude
   * c is the great circle distance in Radians.
   * R is the radius of a spherical Earth.
   * The locations of the two points in
   spherical coordinates (longitude and
   latitude) are lon1,lat1 and lon2, lat2.
   */
   double dDistance = Double.MinValue;
   double dLat1InRad = Lat1 * (Math.PI / 180.0);
   double dLong1InRad = Long1 * (Math.PI / 180.0);
   double dLat2InRad = Lat2 * (Math.PI / 180.0);
   double dLong2InRad = Long2 * (Math.PI / 180.0);

   double dLongitude = dLong2InRad - dLong1InRad;
   double dLatitude = dLat2InRad - dLat1InRad;

   // Intermediate result a.
   double a = Math.Pow(Math.Sin(dLatitude / 2.0), 2.0) +
   Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) *
   Math.Pow(Math.Sin(dLongitude / 2.0), 2.0);
// Intermediate result c (great circle distance in Radians).
double c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a));

// Distance.
// const Double kEarthRadiusMiles = 3956.0;
const Double kEarthRadiusKms = 6376.5;
dDistance = kEarthRadiusKms * c;

return dDistance;
}

public static double Calc(string NS1, double Lat1, double Lat1Min,
string EW1, double Long1, double Long1Min, string NS2,
double Lat2, double Lat2Min, string EW2,
double Long2, double Long2Min)
{
double NS1Sign = NS1.ToUpper() == "N" ? 1.0 : -1.0;
double EW1Sign = NS1.ToUpper() == "E" ? 1.0 : -1.0;
double NS2Sign = NS2.ToUpper() == "N" ? 1.0 : -1.0;
double EW2Sign = EW2.ToUpper() == "E" ? 1.0 : -1.0;
return (Calc(
(Lat1 + (Lat1Min / 60)) * NS1Sign,
(Long1 + (Long1Min / 60)) * EW1Sign,
(Lat2 + (Lat2Min / 60)) * NS2Sign,
(Long2 + (Long2Min / 60)) * EW2Sign
));
}
=> Shabdar (Wednesday 09-Apr-08 09:52 AM)



       Example usage of this class,

       int distance = CDistanceBetweenLocations.Calc(28.33,-78.55,34.2,-82.11)
       => Shabdar (Wednesday 09-Apr-08 09:54 AM)

          If anyone has a Database of Lat-Long and want to find all the locations with
          X km of a point, you can use this Function to calculate the distance in SQL :

          CREATE FUNCTION [dbo].[udfLatLonRadiusDistance]
          ( @lat1Degrees float
          ,@lon1Degrees float
          ,@lat2Degrees float
          ,@lon2Degrees float )
RETURNS float
AS
BEGIN

DECLARE @earthSphereRadiusNauticalMiles as float
DECLARE @nauticalMileConversionToMilesFactor as float
SELECT @earthSphereRadiusNauticalMiles = 6366.707019
SELECT @nauticalMileConversionToMilesFactor = .621371

-- convert degrees to radians
DECLARE @lat1Radians float
DECLARE @lon1Radians float
DECLARE @lat2Radians float
DECLARE @lon2Radians float
SELECT @lat1Radians = (@lat1Degrees / 180) * PI()
SELECT @lon1Radians = (@lon1Degrees / 180) * PI()
SELECT @lat2Radians = (@lat2Degrees / 180) * PI()
SELECT @lon2Radians = (@lon2Degrees / 180) * PI()

-- formula for distance from [lat1,lon1] to [lat2,lon2]
RETURN ROUND(2 * ASIN(SQRT(POWER(SIN((@lat1Radians -
@lat2Radians) / 2) ,2)
+ COS(@lat1Radians) * COS(@lat2Radians) *
POWER(SIN((@lon1Radians - @lon2Radians) / 2), 2)))
* (@earthSphereRadiusNauticalMiles *
@nauticalMileConversionToMilesFactor), 4)

END


------ The Stored Procedure you would use to find all the Retailers within X
kilometres :

CREATE PROCEDURE [dbo].[proc_RetailersInRange](
@Lon float
,@Lat float
,@DistanceMiles float
,@TopX
)
AS
BEGIN
SELECT TOP @TopX RetailerID, RetailerName -- <-- YOUR FIELDS
HERE
-- Distance In Miles
, dbo.udfLatLonRadiusDistance(RetailerLatitude,RetailerLongitude,@Lat,
      @Lon) AS DistanceMiles
      -- Distance in Km
      , dbo.udfLatLonRadiusDistance(RetailerLatitude,RetailerLongitude,@Lat,
      @Lon)*1.61 AS DistanceKm

      FROM RETAILERS -- <-- YOUR TABLE NAME HERE
      WHERE
      dbo.udfLatLonRadiusDistance(RetailerLatitude,RetailerLongitude,@Lat,
      @Lon) < @DistanceMiles
      ORDER BY DistanceMiles ASC
      END

      --OUTPUT:
      /* RetailerID | RetailerName | DistanceMiles | DistanceKm
      ABC123 | ABC Company | 10 | 16
      BCA123 | BCA Company | 20 | 32
      CCC123 | CCC Company | 25 | 40
      ABC123 | ABC Company | 31 | 46.6
      => Atomiton (Friday 18-Apr-08 05:04 PM)



Distance calculation VB dot net


Imports System
Imports System.Text
Public Class CalCulateDistanceBeteenTwoPoints
'Use following class to calculate distance between two geopoints. It returns distance
in kilometers,

Public Shared Function CalculateDistance(ByVal Lat1 As Double, ByVal Long1
As Double, ByVal Lat2 As Double, ByVal Long2 As Double) As Double

Dim dDistance As Double = Double.MinValue
Dim dLat1InRad As Double = Lat1 * (Math.PI / 180.0)
Dim dLong1InRad As Double = Long1 * (Math.PI / 180.0)
Dim dLat2InRad As Double = Lat2 * (Math.PI / 180.0)
Dim dLong2InRad As Double = Long2 * (Math.PI / 180.0)

Dim dLongitude As Double = dLong2InRad - dLong1InRad
Dim dLatitude As Double = dLat2InRad - dLat1InRad

Dim a As Double = Math.Pow(Math.Sin(dLatitude / 2.0), 2.0) +
Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) *
   Math.Pow(Math.Sin(dLongitude / 2.0), 2.0)
   Dim c As Double = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a))

   Const kEarthRadiusMiles As Double = 3956.0
   Const kEarthRadiusKms As Double = 6376.5

   dDistance = kEarthRadiusKms * c

   Return dDistance
   End Function
   End Class
   => waseem Akhtar (Tuesday 21-Oct-08 11:57 PM)



Dear Sir,

Thanks a lot... for your Google Map Control.

I have implemented your Google Map Control and it's working fine.
But now i want to point an exact location in that Google Map when that map opens For
Ex:- Vasant Kunj in Delhi.


Pls. guide me.



Thanks in advance.
=> Girish Rawat (Thursday 10-Apr-08 02:49 AM)

   You need to find latitude and longitude for the address you want to show on map.
   And then you can set map's center point on this latitude and longitude. Or you can
   display icon on that point.

   Right now this control does not support geocoding. I.e, you can not find latitude and
   longitude based on an address. But in future version it will support this feature.
   Infact I have implemented it, but could not get time to release a new version. You
   can expect this version in couple of days.
   => Shabdar (Thursday 10-Apr-08 10:45 AM)



   plz tell me how i downloads the asp.net google map control and how i use goolle
   maps like u plz dear
   i m in trouble i m working currently in Gexton software house as ASP.NET
   programer
   => samiullah (Saturday 12-Apr-08 04:36 AM)



I really like your control, fantastic. One of the things it doesn't do that I use a lot in
Google Maps is zoom and centre on the map automatically. Its really useful if you are
populating a map dynamically from a database.

any how, rather than asking you to do it - I've done it myself and extended your control
with some extra properties :) It was that nicely put together you made it easy for me :)

I added three new properties:
.SnapToBounds
.SnapToBoundsZoomLevel
.SnapToBoundsZoomLevelIgnore

You can download the files from psykoptic.com/GoogleMapControl-
ForceToBounds.zip

I've included a new example page showing it working:
/SnapToBounds.aspx

Many thanks - let me know if you find it useful!
=> Darren (Thursday 10-Apr-08 06:41 PM)

   Thanks Darren for adding extra functionality to this control. I will consider adding
   these properties in next release.
   => Shabdar (Friday 11-Apr-08 10:17 AM)

       My pleasure - I'm looking forward seeing what you come up with over future
       releases. I'll definately be using your control for my next Google Maps
       implementation. Its simple to use, but cleverly implemented. I like it!
       => Darren (Friday 11-Apr-08 01:14 PM)



Whoops, just realised quite a few posts on your blog where about using getBounds, aaah
well, its done now.

(it only works for markers though - not polylines)
=> Darren (Thursday 10-Apr-08 06:45 PM)
Hi

First I wanted to say thanks a lot for the the time that you have spent on the control and
for making it available for others to use - much appreciated.

I'm just starting to use Ajax and have a quick question regarding the script manager.

I have two dropdownlists that I am using to refresh co-ordinates on the map. I would
like them to appear above the map object itself and enclose them in an Update Panel, but
that means that I must insert the scripting manager above the update panel, which
therefor places the map above the dropdownlists...

Are you able to provide any suggestions? I was thinking that I could use a nested
content page (if that's even possible) to get around this issue, or maybe I'm not
understanding it properly, but was hoping for a bit of advice...

Thanks again
=> Brian (Thursday 10-Apr-08 06:49 PM)

     Hi Brian

     This is one of the limitation of this control. I noticed it during my testing. If you
     want to insert some ajax control before map, it's not possible. Because control has a
     script manager, which will not allow you to insert another script manager on page.

     To solve this problem, you can use inside control, which allows you to insert on
     page.

     Go to GoogleMapControl.aspx source and replace following code,




     with
After doing this you can insert object at the start of your page.
=> Shabdar (Friday 11-Apr-08 10:15 AM)

   Hi

   Thanks a lot for the quick reply. It's working now for me but just to clarify for
   anyone else with this problem, the code that you paste in should read as follows:




   Thanks again for your help
   => Brian (Friday 11-Apr-08 01:13 PM)

        Hi there. Great Control!!! I was using the SubGurim control which is
        feature-rich but harder to get started using.

        I encountered this problem as well. I MIGHT recommend that you NOT use
        a ScriptManager and DEFAULT to a ScriptManagerProxy. Make it part of
        the implementation procedure that you NEED a ScriptManager on the Page
        (or the Master Page).

        The Only problem I'm having after changing SCriptManager to
        ScriptManagerProxy was a JAvaScript Error of "GService is not defined"

        I think it might have to with PageMEthods, but I'm not sure.

        => ATomiton (Friday 18-Apr-08 04:50 PM)



   Hello All

   I put this Code in my GoogleMapForASPNet.ascx.
         I am using a DotNetNuke.It work fine in the local server but when i upload a
         site online it not found the Gservice.asmx and it give a Error

         GService is not defined
         Source File:
         http://dnndev.engineering.com/DesktopModules/UniversityRankings/GoogleMa
         pAPIWrapper.js
         .............




         => vivek (Monday 06-Oct-08 05:30 AM)



Hi,

I'm pretty sure I followed your instructions for setting up the project. But when I try and
compile the project I get a "GoogleObject" could not be found in the
GoogleMapForASPNet user control.

Any ideas?

Thanks!
Eric
=> Eric Odom (Thursday 10-Apr-08 06:54 PM)

      Eric,

      Make sure that you have copied following files in App_Code directory, not in root
      directory.

      GoogleMap.cs
      GService.cs

      These files should not go in Root Directory of your website.
      => Shabdar (Friday 11-Apr-08 10:20 AM)
       i need to google map calculate between two location .

       if u have any sample for that plz send me ..

       waiting for response...

       Hitesh
       => Hitesh (Friday 11-Apr-08 11:51 AM)

          Did you mean calculate distance between two locations?

          I have provided class for that. See my reply for Revathi above.
          => Shabdar (Friday 11-Apr-08 03:47 PM)



Hi,
I'm trying to use your Google Maps Control but I get the Error-message:
GoogleMapForASPNet is not defined. What can I do. Sorry I'm new in .net.
Ralf
=> Ralf (Saturday 12-Apr-08 09:16 AM)



Yesterday I have found your website. I'm very interested in using it. It's great work.

I have followed the steps as written above. However each time I open
GoogleMapForASPNet.ascx Microsoft Visual Studio crashes and restarts.

Do you have any idea what is going wrong. I have been working on it since yesterday,
but can't get it working.

Thank you for your help.

I'm using ASP.NET 3.5 with AJAX. I'm programming in Visual Studio 2008.
=> Robert (Monday 14-Apr-08 07:17 AM)

   I tested it with Visual Studio 2008 on my maching it works fine. You just need to
   convert it to .Net Framework 3.5.

   I have uploaded Visual Studio 2008 version of this control. You can download it
   from following link,
downloads/GoogleMapControl_VS2008.zip

Copy paste above link in your browser address bar to download.
=> Shabdar (Monday 14-Apr-08 09:10 AM)

   Thanks a lot for your quick reply.

   I have downloaded the file and extracted it. However it still crashes when I open
   GoogleMapForASPNet.ascx. It take about 15 seconds and then Visual Studio
   crashes. I have asked a friend to try it on his machine and also his Visual Studio
   crashes. Could you please try it again? It does take a few seconds before it
   crashes.

   Thanks a lot.

   Best wishes,

   Robert
   => Robert (Monday 14-Apr-08 10:04 AM)

      Hi Robert,

      Ok I got that error now. This error occurs when you try to open Control in
      Design Mode. But if you run it without opening it in design mode, it works
      fine. So temporary work around is not to open it in design mode. If you
      need to make any changes in control, then use source view.

      I don't know exact reason behind this error. But when I see error report, it
      says it has caused some error in shlwapi.dll.

      This seems to be known bug with Visual Studio 2008. Many people have
      reported this. Here is one of the forum that discusses it.

      http://www.velocityreviews.com/forums/t186947-explorer-has-caused-an-
      error-in-shlwapidll.html
      => Shabdar (Monday 14-Apr-08 11:02 AM)

          Hi Shabdar,

          Thanks a lot.

          I'm afraid the error also occurs in source mode. It only takes a bit longer
          to occur. My friend also reported it was working in first instance, but
when he waited a bit longer in source code it also crashed.

I also think it's a Visual Studio 2008 bug. I'm not sure if you have a
solution for this. If you have, please let me know.

Best wishes,

Robert.
=> Robert (Monday 14-Apr-08 11:29 AM)

   I don't have any solution now, but will take a look and respond if I
   get anything.
   => Shabdar (Monday 14-Apr-08 01:11 PM)

       One thing to note if you're already using asp.net AJAX with
       .Net 3.5. Delete the following line (above ScriptManagerProxy)
       which refers to .Net 2.0 Ajax :

       <%@ Register Assembly="System.Web.Extensions,
       Version=1.0.61025.0, Culture=neutral,
       PublicKeyToken=31bf3856ad364e35"
       Namespace="System.Web.UI" TagPrefix="asp" %>


       Ajax is built into .Net 3.5 and Version 1.0.61025 is .Net 2.0's
       version.

       This code is in: GoogleMapForASPNet.ascx
       => Atomiton (Friday 18-Apr-08 05:20 PM)

          Thanx for all you help.

          I'm still getting this error. Only when I delete all the
          javascript in the GoogleMapForASPNet.ascx it doesn't
          crash. When I then add (without any code) it crashed
          immediately.

          I have tried to solve this problem within all my powers,
          however I didn't find the solution.

          I would be really gratefull if someone could help me out.
                        Thanks a million.

                        Best wishes,

                        Robert.
                        => Robert (Sunday 20-Apr-08 12:31 PM)

                            I kind of solved it. After some trial and error I have
                            deleted:
                            in the GoogleMapForASPNet.ascx.

                            Now it seems to be working and it doesn't crash
                            anymore. However sure this code was meant for
                            something. Could someone explain me what this code
                            was for?

                            Thanks in advance.

                            Robert.
                            => robert (Monday 21-Apr-08 05:36 AM)

                               You can remove that line. I didn't know that it's
                               going to cause error in VS2008. I added that line
                               originally thinking that I might make ajax calls in
                               GoogleMapForASPNet.ascx.cs code as well. But
                               than I never used it. SO it is safe to remove that line.
                               => Shabdar (Monday 21-Apr-08 11:36 AM)




When trying to plot some data point (total apprx. 2000 in number) on the map, it gives
the following error:

The server method 'GetGoogleObject' failed with the following error:
System.InvalidOperationException-- Maximum length exceeded
=> Sudipta (Tuesday 15-Apr-08 06:41 AM)

   Here is the solution to this problem.

   This happens because this control uses lot of ajax calls. And Ajax causes lot of
   serialization and deserialization. But there is a limit on this. You need to increase
   this limit in Web.Config. Here is how to do that.
Go to your Web.Config file. Add sections shown below. In jsonSerialization section
set maxJsonLength="500000". If you still get this error, increase maxJsonLength.

=========================Web.Config==========================
=======================




type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">

type="System.Web.Configuration.ScriptingSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">

type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication"/>

type="System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35">

type="System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false" allowDefinition="Everywhere" />

type="System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />

type="System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />
   Add following section outside section.




   => Shabdar (Monday 21-Apr-08 11:43 AM)



   The server method 'GetGoogleObject' failed with the following error:
   System.InvalidOperationException-- Maximum length exceeded


   Does anyone have a solution to this problem?
   => Tejal Gandhi (Thursday 30-Oct-08 03:06 PM)



Did you by any chance make a Google Chart Wrapper too? :)
=> Alex (Thursday 17-Apr-08 11:49 AM)
Hi
I'm working on VS.Net Desktop application to display Google Map. Its work fine for
me. I have a question Is it possible to overly my kml file in my desktop application? if
so can any one please guide me how to solve with code snippet.

Regards
sonj
=> sonj (Friday 18-Apr-08 01:59 AM)



Hi
First of all thank you for this great control.
You have written in a previous comment that:
{
This is a good suggestion to move map dynamically when pushpins are not withing map
area. I will add this feature in next release. But for now you can apply following
solution.

Add an Ajax Timer control on your webpage where you have inserted google map
control. On Timer_Tick event, set center point of map to your vehicle position.

Example,

protected void Timer1_Tick()
{
GoogleMapForAspNet1.GoogleMapObject.CenterPoint =
GoogleMapForAspNet1.GoogleMapObject.Points["YourVehiclePushpinId"];
}

This will move map to accomodate your vehicle position. This is not the best solution,
but use it for now.
}

I have tried this but it does not works. Can you please help me.
=> azeem (Saturday 19-Apr-08 08:01 AM)



Your control is just great. A wonderful asset to the open source community. Thank you.

As I understood the control doesn't support geocoding yet. However I read the good
news that it is available, but yet not published.

Is it possible to publish a pre-release? I would really like to use the geocoding function
together with this control.

Thanks,

Robert.
=> Robert Smit (Monday 21-Apr-08 11:14 AM)

   I am not getting enough time to release a new version. For now you can use
   following function to geocode an address. It takes GooglePoint and GoogleApiKey
   as arguments. Add this function in cCommon class as static function.



   public static bool GeocodeAddress(GooglePoint GP,string GoogleAPIKey)
   {
   string sURL = "http://maps.google.com/maps/geo?q=" + GP.Address +
   "&output=xml&key=" + GoogleAPIKey;
   WebRequest request = WebRequest.Create(sURL);
   request.Timeout = 10000;
   // Set the Method property of the request to POST.
   request.Method = "POST";
   // Create POST data and convert it to a byte array.
   string postData = "This is a test that posts this string to a Web server.";
   byte[] byteArray = Encoding.UTF8.GetBytes(postData);
   // Set the ContentType property of the WebRequest.
   request.ContentType = "application/x-www-form-urlencoded";
   // Set the ContentLength property of the WebRequest.
   request.ContentLength = byteArray.Length;
   // Get the request stream.
   Stream dataStream = request.GetRequestStream();

   // Write the data to the request stream.
   dataStream.Write(byteArray, 0, byteArray.Length);
   // Close the Stream object.
   dataStream.Close();
   // Get the response.
   WebResponse response = request.GetResponse();
   // Display the status.
   //Console.WriteLine(((HttpWebResponse)response).StatusDescription);
   // Get the stream containing content returned by the server.
   dataStream = response.GetResponseStream();
   // Open the stream using a StreamReader for easy access.
   StreamReader reader = new StreamReader(dataStream);
   // Read the content.
   string responseFromServer = reader.ReadToEnd();
StringReader tx = new StringReader(responseFromServer) ;

//return false;
//System.Xml.XmlReader xr = new System.Xml.XmlReader();

//return false;

DataSet DS = new DataSet();
DS.ReadXml(tx);
//DS.ReadXml(dataStream);
//DS.ReadXml(tx);



int StatusCode =
cCommon.GetIntegerValue(DS.Tables["Status"].Rows[0]["code"]);
if (StatusCode == 200)
{
string sLatLon =
cCommon.GetStringValue(DS.Tables["Point"].Rows[0]["coordinates"]);
string[] s = sLatLon.Split(',');
if (s.Length > 1)
{
GP.Latitude = cCommon.GetNumericValue(s[1]);
GP.Longitude = cCommon.GetNumericValue(s[0]);
}
GP.Address =
cCommon.GetStringValue(DS.Tables["Placemark"].Rows[0]["address"]) + " " +
cCommon.GetStringValue(DS.Tables["PostalCode"].Rows[0]["PostalCodeNumber
"]);
return true;
}
return false;

}

You need to add following property in GooglePoint class,

string _address = "";
public string Address
{
get { return _address; }
set { _address = value; }
}
You can find GooglePoint class in cGoogleMap.cs file.

After doing this you can geocode an address in following way,

Initialize a GooglePoint object with just Address and ID. Then call
GeocodeAddress() function with this GooglePoint,

GooglePoint GP = new GooglePoint();
GP.Address = "";
GP.ID = "Point1";

cCommon.GeocodeAddress(GP,"");
=> Shabdar (Monday 21-Apr-08 11:53 AM)

   After this function call check Latitude & Longitude.
   => Shabdar (Monday 21-Apr-08 11:56 AM)

      Thanks for this post! Just thought I'd let you know that:
      GetIntegerValue(), GetStringValue(), and GetNumericValue() are needed
      for this method to work.

      I'd imagine they're simple Converter methods.
      => Atomiton (Monday 21-Apr-08 05:23 PM)

          Oops! I just copy pasted this code from my working project.

          Yes, those are converter methods. Here they are. Copy them in
          cCommon.cs file,

          public static string GetStringValue(object obj)
          {
          if (obj == null)
          {
          return "";
          }
          if ((obj == null))
          {
          return "";
          }
          if (!(obj == null))
          {
          return obj.ToString();
          }
else
{
return "";
}
}

public static double GetNumericValue(object pNumValue)
{
if ((pNumValue == null))
{
return 0;
}
if (IsNumeric(pNumValue))
{
return double.Parse((pNumValue.ToString()));
}
else
{
return 0;
}
}

public static int GetIntegerValue(object pNumValue)
{
if ((pNumValue == null))
{
return 0;
}
if (IsNumeric(pNumValue))
{
return int.Parse((pNumValue.ToString()));
}
else
{
return 0;
}
=> Shabdar (Tuesday 22-Apr-08 09:09 AM)

   Cool. That's what I thought. (PS, you're missing a closing squiggly
   bracket and now using an IsNumeric method) Hehe... you know
   when you fix one problem, you always bring up another one. lol.

   I'm curious why use an IsNumeric Helper method though, instead of
   just using int.TryParse()
                  int result;
                  if (int.TryParse("123", out result))
                  {
                  Debug.WriteLine("Valid integer: " + result);
                  }
                  else
                  {
                  Debug.WriteLine("Not a valid integer");
                  => ATomiton (Tuesday 22-Apr-08 11:01 AM)

                      Thanks I have learned something new today.
                      => Shabdar (Tuesday 22-Apr-08 03:33 PM)




I have been using your control and have been able to use some of its functionality.
When I am loading points on the map, i would like to display to the user a "please
wait.." until it loads. I know there is no built in fucntionality in the .net control. Do you
know of any practical solution to do this?
=> Carl (Monday 21-Apr-08 03:43 PM)



Hi. Great control. Thanks for building this. I wonder if you have a tutorial or directions
on how to bind a SQL table to the map for the points? I'm having a little trouble getting
it to work. Thanks!
=> Chris Bloom (Tuesday 22-Apr-08 10:58 AM)

   I've done this. It's pretty simple. Have you got the Longitide and Latitude in the
   Table?

   If so, There is a stored Procedure and Function above that will help you calculate
   distance. Just pass in a Lat and Lon to the SP and it will return the values that you
   need from the table. Once you have the table results, just iterate through them and
   make a new GPoint for each entry.

   What exactly are you trying to do, display everything from the table?
   => Atomiton (Tuesday 22-Apr-08 11:05 AM)

       Thanks for the response. Yes, I have a fairly large database with many "sites" in
       it. I'm querying out the sites based upon who the logged in user is. This map
will display the current customer's sites. The procedure I'm using to return the
table includes a unique SiteID, Lat, Long, Site Name, Site Number, etc.

I'm just not sure how to tell the map to use the stored procedure as it's data
source for the points.

Thanks.
=> Chris Bloom (Tuesday 22-Apr-08 12:06 PM)

   OK, I figured it out. I thought I would post this code just in case someone
   else wants to do the same thing. I wanted to pull a listing of sites from my
   database and put them on the map. Here's how i did it, using VB.NET:

   Private Sub FillMapAllSites()
   'Setting up the data view and data row that we'll read through for the
   pushpins.
   'SQLDatasource1 is our datasource on the page with the connection string
   and select command
   'that points back to our stored procedure.
   Dim vwSites As Data.DataView =
   CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty),
   Data.DataView)
   Dim dr As Data.DataRow

   'rowindex is just a unique identifier of each pin. Cannot use SiteID - will
   throw an exception because the
   'SiteID value is greater than the number of rows in the array that contains
   the pushpins.
   Dim rowindex As Integer = 0

   'Setting the path of the icon to use. This is relative to the root directory.
   Dim siteIconPath As String = "Images/Icons/BlackTower.png"

   'This is the loop that runs through the view above, row by row.
   '*****BEGIN LOOP*****
   For Each dr In vwSites.Table.Rows 'for each row in the view
   'set up the variables that will hold our specific values
   Dim txtHTML, txtTooltip, txtSiteName, txtSiteNumber, txtFCCNumber As
   String
   Dim dbLatitude, dbLongitude As Double
   Dim GP As New GooglePoint() 'specific to the GooglePoint Class in
   App_Data directory

   'Getting the values from each row's item with each column name, and
         converting them to a string
         txtSiteName = RTrim(dr.Item("SiteName").ToString)
         txtSiteNumber = RTrim(dr.Item("SiteNumber").ToString)
         txtFCCNumber = RTrim(dr.Item("FCC_REGISTRATION").ToString)

         'Getting Latitude and Longitude, making sure they are converted to double
         'WILL THROW ERROR if Latitude or Longitude are zero or null.
         dbLatitude = CType(dr.Item("Latitude"), Double)
         dbLongitude = CType(dr.Item("Longitude"), Double)

         txtHTML = "" + txtSiteName + "
         FCC #" + txtFCCNumber
         txtTooltip = txtSiteName + " - " + txtFCCNumber

         'Below are the parameters accepted by the GooglePoint class
         GP.ID = rowindex '***REQUIRED***
         GP.Latitude = dbLatitude '***REQUIRED***
         GP.Longitude = dbLongitude '***REQUIRED***
         GP.IconImage = siteIconPath '***OPTIONAL***
         GP.InfoHTML = txtHTML '***OPTIONAL***
         GP.ToolTip = txtTooltip '***OPTIONAL***
         GP.IconImageWidth = 20 '***OPTIONAL***
         GP.IconImageHeight = 38 '***OPTIONAL***

         'now add values from above to a new point on the Map
         GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP)

         'increment the rowindex for the next iteration. Rowindex must be unique for
         each pushpin.
         rowindex = rowindex + 1
         Next
         '****** END LOOP ******

         'For fun, let's just display how many sites we found
         Label1.Text = rowindex.ToString + " Total Sites"

         End Sub
         => Chris Bloom (Wednesday 23-Apr-08 02:25 PM)



Seems to be a pretty cool tool for GMaps, but when I try to open
GoogleMapForASPNet.aspx in VS2008 it causes VS2008 to flicker and then crash. Any
idea why?
=> Dewayne (Tuesday 22-Apr-08 03:06 PM)
Duhhh. I read your replies above and will implement those changes.
=> Dewayne (Tuesday 22-Apr-08 03:18 PM)


   Hi,

   This is really cool :-)

   Is it possible to draw circles instead of polygons ?

   Kind regards
   Morten / Denmark
   => Morten (Tuesday 22-Apr-08 05:27 PM)



   Hi Shabdar,

   Thank you for your control, it is very good.
   I have an application to monitor 5-10 vehicles that move all day and I want to
   use your control. I project the vehicles initially on the map but when new
   positions arrive in my database the new points are added on the map and not just
   refreshed. Could you please give me a hand on that?

   Thank you

   Costas
   => Costas Bouros (Wednesday 23-Apr-08 08:35 AM)



   OK - I was able to get the data loaded into the map, put the code above...but now
   there's something else I would like to do:

   Is there a way to expose the PinID that is selected on the google map? I would
   like to have an event fire that will allow me to capture that pinID and requery
   my DB with additional details about that pin (or Site in my case).

   Is this possible?

   Thanks
   => Chris Bloom (Wednesday 23-Apr-08 02:32 PM)
As per your guide i place the function fGetGoogleObjectOptimized(result,
userContext)
{
map.setCenter(new GLatLng(result.CenterPoint.Latitude,
result.CenterPoint.Longitude), result.ZoomLevel);
.
.//Keep rest of the code as it is
.
} this function to .ascx page but not placing updated(new) point as center. I only
need to drag manually p to get that point.
=> Sridhar (Thursday 24-Apr-08 09:10 AM)



The type or namespace name 'GoogleObject' could not be found (are you
missing a using directive or an assembly reference?)

why i got this error?
help me!
=> nur (Sunday 27-Apr-08 02:17 AM)

   Hi;

   I'm new with Google Maps Control and when I tried to compile it I get this
   error "The type or namespace name 'GoogleObject' could not be found (are
   you missing a using directive or an assembly reference?)". Please help me I
   really wanted to try your control.

   Thank you
   => Rico (Friday 23-May-08 03:30 AM)

         Want to download dll for Google.KML
         => sandeep kumar (Thursday 11-Sep-08 09:19 AM)



As per your guide i place the function fGetGoogleObjectOptimized(result,
userContext)
{
map.setCenter(new GLatLng(result.CenterPoint.Latitude,
result.CenterPoint.Longitude), result.ZoomLevel);
.
.//Keep rest of the code as it is
.
} this function to .ascx page but not placing updated(new) point as center. I only
need to drag manually to get that point.
=> sridhar (Tuesday 29-Apr-08 12:42 AM)



unction fGetGoogleObjectOptimized(result, userContext)
{
map.setCenter(new GLatLng(result.CenterPoint.Latitude,
result.CenterPoint.Longitude), result.ZoomLevel);
.
.//Keep rest of the code as it is
.
Can you explain me what i need to send two parameter (result , usercontext)
=> Sridhar (Tuesday 29-Apr-08 01:04 AM)



Hi,
I try to use this fantastic control with VB.NET in VS2008. But I get the message
'GooglePoint is not defined'. Can you helb me? With C# it works fine but I can't
programm in C#.
Thank you
=> Ralf (Wednesday 30-Apr-08 04:59 AM)

      The error-message is 'GoogleMapForASPNet is not defined'. Can anyone
      please help me to use this control in VB.Net?
      Thank you
      Ralf
      => Ralf (Thursday 01-May-08 02:37 AM)



Hi

your control is working,
can i add pushpin using address.
can i find longitude adn latitude from address.
=> padma (Saturday 03-May-08 12:32 AM)



Hi,

i tried to change the default google map to satellite with this:
GoogleMapForASPNet1.GoogleMapObject.MapType=
GoogleMapType.SATELLITE_MAP;

but it semms it doesnt work!
Any idea??
=> george (Monday 05-May-08 05:32 AM)

   Hi George,

   Did you ever get a solution to setting the Maptype? I am having the same
   problem attempting to set to the MapType =
   GoogleMapType.HYBRID_MAP;
   => Chris Mangiapane (Sunday 11-May-08 03:04 PM)

       Seems to be fix in v1.4. Thanks
       => Chris Mangiapane (Sunday 18-May-08 10:34 AM)



Hai shabdar,

I would like to get the place name in gmap eg: If i pass the latitude and longitude
nearest landmark or area name need to get display
=> sridhar (Tuesday 06-May-08 04:36 AM)



As per your guide i place the following function
fGetGoogleObjectOptimized(result, userContext)
{
map.setCenter(new GLatLng(result.CenterPoint.Latitude,
result.CenterPoint.Longitude), result.ZoomLevel);
.
.//Keep rest of the code as it is
.
} to .ascx page but not placing updated(new) point as center. I only need to drag
manually to get that point. And may i know what is parameter (result)
=> srisant (Wednesday 07-May-08 08:15 AM)



I want to use city name or loaction instead of longitude what code i use
=> Usman (Thursday 08-May-08 02:49 AM)
   Why don't you read through the posts that have already been made? This
   question has already been answered. I am in no way associated with this
   control, but I assume that it's rather annoying to have the same question
   asked several times just because people are too lazy to do a bit of research
   or reading on their own. He has been kind enough to make this control
   available for free - the least you can do is to read what has already been
   posted.
   => Brian (Thursday 08-May-08 07:46 AM)

      Sir i can see this solution of address giving instead of longitude or
      latitude .Kindly give me code to use only address(city or town
      name)only beacuse i donot know the longitude or lat of location so i
      want a code that show the map throug parameter as loaction(city or
      town).
      => usman (Thursday 08-May-08 02:02 PM)



Hi Shabdar,
your code is great thx.But I have a problem.Now I want to focus on my ship and
done this but infohtml window doesnt show.I set this codes

Forexample:
GoogleMapControl1.GoogleMapObject.CenterPoint.Latitude =
GoogleMapControl1.GoogleMapObject.Points["11"].Latitude;
GoogleMapControl1.GoogleMapObject.CenterPoint.Longitude =
GoogleMapControl1.GoogleMapObject.Points["11"].Longitude;
GoogleMapControl1.GoogleMapObject.CenterPoint.InfoHTML =
GoogleMapControl1.GoogleMapObject.Points["11"].InfoHTML;
GoogleMapControl1.GoogleMapObject.ZoomLevel = 10;
GoogleMapControl1.GoogleMapObject.RecenterMap = true;

This is work but infowindow doesnt show.How can I do this?

Best regards,
=> Bahadir (Thursday 08-May-08 10:07 AM)



Hi shabdar,
I received your mail message thx for giving.Here is my code:

protected void Page_Load(object sender, EventArgs e)
{
GoogleMapControl1.GoogleMapObject.APIKey =
WebConfigurationManager.AppSettings["GoogleAPIKey"];
GoogleMapControl1.GoogleMapObject.APIVersion = "2";
GoogleMapControl1.GoogleMapObject.CenterPoint.Latitude = 38.4;
GoogleMapControl1.GoogleMapObject.CenterPoint.Longitude = 31.5;
GoogleMapControl1.GoogleMapObject.Width = "500";
GoogleMapControl1.GoogleMapObject.Height = "600px";
GoogleMapControl1.GoogleMapObject.ZoomLevel = 6;


string query = "SELECT TOP(5) *FROM dbo.AISList WHERE (Lat IS NOT
NULL) AND (Lon IS NOT NULL)";

SqlConnection connectSql = new SqlConnection(AISDBConnection);
SqlCommand commandSql = new SqlCommand(query, connectSql);

SqlDataReader reader;

connectSql.Open();
reader = commandSql.ExecuteReader();
while (reader.Read())
{

GooglePoint d = new GooglePoint();
d.ID = reader["MMSI"].ToString();
d.Latitude = Convert.ToDouble(reader["Lat"].ToString());
d.Longitude = Convert.ToDouble(reader["Lon"].ToString());
d.InfoHTML = CreateDetailVesselWindow(
ControlNulls(reader["Name"].ToString())
, ControlNulls(reader["MMSI"].ToString())
, ControlNulls(reader["CallSign"].ToString())
, ControlNulls(reader["IMO"].ToString())
, ControlNulls(reader["Destination"].ToString())
, ControlNulls((VesselTypes(reader["ShipAndCargo"].ToString())))
, ControlNulls(reader["Draught"].ToString())
, ControlNulls(reader["SOG"].ToString())
, ControlNulls(reader["DimB"].ToString())
, ControlNulls(reader["DimD"].ToString())
);
d.ShadowIcon = "blank.png";
GoogleMapControl1.GoogleMapObject.Points.Add(d);
}
reader.Close();
connectSql.Close();
}
protected void Button1_Click1(object sender, EventArgs e)
{
GoogleMapControl1.GoogleMapObject.CenterPoint.Latitude =
GoogleMapControl1.GoogleMapObject.Points["1193046"].Latitude;
GoogleMapControl1.GoogleMapObject.CenterPoint.Longitude =
GoogleMapControl1.GoogleMapObject.Points["1193046"].Longitude;
//GoogleMapControl1.GoogleMapObject.CenterPoint.InfoHTML =
GoogleMapControl1.GoogleMapObject.Points["11"].InfoHTML;
GoogleMapControl1.GoogleMapObject.ZoomLevel = 10;
GoogleMapControl1.GoogleMapObject.RecenterMap = true;
}

AND I changed googlemaps js codes below this:

map.enableDoubleClickZoom();
map.enableScrollWheelZoom();
//map.enableContinuousZoom();
map.addMapType(G_PHYSICAL_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.addControl(new GOverviewMapControl());

But I didn't :(


=> bahadir (Thursday 08-May-08 02:57 PM)



hello¡Ishabdar

i thinik the points have a little bug

in GoogleMapForASPNET.ascx file

you can find

GEvent.addListener(marker, "dragend", function() {
GService.SetLatLon(this.value,this.getLatLng().x(),this.getLatLng().y);RaiseEv
ent('PushpinMoved',this.value); });

getLatLng().y is not google map Events

you can fix it with this.getLatLng().lat()
like:
GEvent.addListener(marker, "dragend", function() {
GService.SetLatLon(this.value,this.getLatLng().lat(),this.getLatLng().lng());Rai
seEvent('PushpinMoved',this.value); });

now you can know the ponint dragend.
Lat and Lng Values.

Thanks you
=> a926 (Friday 09-May-08 07:52 AM)

      Hi!
      => yakida (Tuesday 10-Jun-08 06:06 AM)



Hi,

How do I remove the shadow image of a PushPin and have the InfoHTML
popup on the right point on the map? I have set my own 10px image and the
shadow PushPins display off the to bootom right.
=> Chris Mangiapane (Sunday 11-May-08 03:50 PM)

      to remove the shadow of default marker ,you need to do fallowing changes:
      go to->googlemapforaspnet.ascx
      go to->function fGetGoogleObject(result, userContext)

      and add the fallowing lines after myIcon_google = new
      GIcon(G_DEFAULT_ICON);



      myIcon_google.iconSize.width=0;
      myIcon_google.iconSize.height=0;

      myIcon_google.iconAnchor.x=8;
      myIcon_google.iconAnchor.y=8;

      // myIcon_google.infoWindowAnchor.x=1;
      // myIcon_google.infoWindowAnchor.y=4;

      myIcon_google.shadowSize.width=0;
      myIcon_google.shadowSize.height=0;
      => balaji (Wednesday 21-May-08 05:33 AM)
Hai shabdar

Thanks lot for your control, its working well but few problem i am facing can u
give me solution?

1) In Internet explorer 6.0 its opening in only top left corner of where i control
placed.
2)If i pass new location its not place new point as center i only need to drag
manually to get a new position
As per your guidance i place the function fGetGoogleObjectOptimized(result,
userContext)
{
this.setCenter(new GLatLng(result.CenterPoint.Latitude,
result.CenterPoint.Longitude), result.ZoomLevel);
} this function in .ascx page but i didnt get what parameter i need to pass still i
am unable to solve this problem

Thank you
=> sant (Monday 12-May-08 07:32 AM)

   The problem with (1) is that you are trying to put your map inside a table. I
   had the same problem, something to do with placing javascript inside a
   table, IE doesn't like it.

   Firefox rendered it fine, but IE did not. I don't offer a solution, just a cause.

   Have a great day.
   => Chris Bloom (Monday 12-May-08 07:36 AM)



Hai shabdar,

Thanks providing solution and Service i am required few more detail 1) function
fGetGoogleObjectOptimized(result, userContext)
{
this.setCenter(new GLatLng(result.CenterPoint.Latitude,
result.CenterPoint.Longitude), result.ZoomLevel);

In above function what i need to pass these parameter(result, usercontext)
2) I need to get the nearest city or place name and store to database if i pass the
latitude longitude( i mean in Google earth if enter the city we can get latitude
latitude i wann do reverse)
=> srisant (Monday 12-May-08 11:48 PM)

  Hi, what you are trying to do is called Reverse Geocoding. If you want to
  find an address based on Latitude and Longitude, it's not supported now by
  this control. It's not easy to do. There are many paid services which does
  this. Microsoft Map Point Services is one of them. I will post it here if I find
  a free service.
  => Shabdar (Monday 12-May-08 11:58 PM)

     Hi shabdar,
     Its a great component that you have made. I appreciate ur hard work and
     time spend on making this amazing component. This component has
     been a great help for all the developers that includes me.. I hereby thank
     you and congratulate you for making such a wonderful tool.

     As i was going through the comments and post on this website i saw one
     of the following post.


     I need to get the nearest city or place name and store to database if i pass
     the latitude longitude( i mean in Google earth if enter the city we can get
     latitude latitude i wanna do reverse)

     Your reply to this was
     " Hi, what you are trying to do is called Reverse Geocoding. If you
     want to find an address based on Latitude and Longitude, it's not
     supported now by this control. It's not easy to do. There are many paid
     services which does this. Microsoft Map Point Services is one of them. I
     will post it here if I find a free service."

     I am also looking for the same functionality. If you have found the
     solution for this i would be grateful to you if you share the same us..

     Secondly, I want to implement get directions using this control . Have
     you implemented this function in this code?

     Please do reply when you get time.

     Cheers Keep up the good work man ...

     Regards
Angad

=> Angad (Thursday 28-Aug-08 05:22 AM)



Dear Sir,

I got the same question too.

Is it possible to return an address if any with corresponding to latitude
and longitude?

Thanks in advance.

With kind regards,

Huy
=> Nguyen Xuan Huy (Monday 27-Oct-08 03:12 PM)

   Hi Shabdar and friends
   I have got some good news ... The reverse geocoding is possible
   now...

   it was published in the Google website. the link is as follows
   http://googlegeodevelopers.blogspot.com/2008/10/geocoding-in-
   reverse.html

   I have written a code.. Shabdar you can add this code in your
   upcoming and updated version..

   Add this function in GooglePoint class in cGoogleMap.cs

   public bool ReverseGeocodeAddress(string sAPIKey)
   {
   return cCommon.ReverseGeocodeAddress(this, sAPIKey);
   }

   And Add the following function in the cCommon Class in
   cGoogleMap.cs

   public static bool ReverseGeocodeAddress(GooglePoint GP, string
   GoogleAPIKey)
   {
string sURL =
"http://maps.google.com/maps/geo?output=xml&oe=utf-8&ll=" +
GP.Latitude.ToString() + "," + GP.Longitude.ToString() + "&key="
+ GoogleAPIKey;
WebRequest request = WebRequest.Create(sURL);
request.Timeout = 10000;
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web
server.";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();

// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
//Console.WriteLine(((HttpWebResponse)response).StatusDescripti
on);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();

StringReader tx = new StringReader(responseFromServer);

//return false;
//System.Xml.XmlReader xr = new System.Xml.XmlReader();

//return false;

DataSet DS = new DataSet();
DS.ReadXml(tx);
//DS.ReadXml(dataStream);
//DS.ReadXml(tx);



int StatusCode =
cCommon.GetIntegerValue(DS.Tables["Status"].Rows[0]["code"]);
if (StatusCode == 200)
{
string sLatLon =
cCommon.GetStringValue(DS.Tables["Point"].Rows[0]["coordinate
s"]);
string[] s = sLatLon.Split(',');
//if (s.Length > 1)
//{
// GP.Latitude = cCommon.GetNumericValue(s[1]);
// GP.Longitude = cCommon.GetNumericValue(s[0]);
//}
if (DS.Tables["Placemark"] != null)
{
GP.Address =
cCommon.GetStringValue(DS.Tables["Placemark"].Rows[0]["addr
ess"]);
}
if (DS.Tables["PostalCode"] != null)
{
GP.Address += " " +
cCommon.GetStringValue(DS.Tables["PostalCode"].Rows[0]["Post
alCodeNumber"]);
}
return true;
}
return false;

}

I hope this is gonna help you all..
Thanks a ton Shabdar for this great tool...
Helping a lot in our programming and work...


Regards
Angad Singh Khurana.
=> Angad Singh Khurana (Tuesday 04-Nov-08 06:19 AM)
I have released a new version (1.4) for this control. Many problems reported in
old versions should get resolve in this release. Please feel free to leave your
feedback/suggestions. Thank you.
=> Shabdar (Monday 12-May-08 11:53 PM)



where can i download 1.4 version please reply me in following url only or
where? http://www.shabdar.org/google-maps-user-control-for-ASP-Net-
part1.html
=> srisant (Tuesday 13-May-08 12:39 AM)



Hi,

U r fantastic and also ur solution for google map(for getting 'Latitude-Longitude'
from Address).its working so nicely.
in that solution u use '//geocoder = new GClientGeocoder();' without that it is
also running perfectly ,am i write?

What the difference between below coding and ur? I am confused..
var geocoder = new GClientGeocoder();
geocoder.getLatLng(address1,addToMap);

function addToMap(response)
{
// alert("AddtoMap");
if(response==null)
{
alert("Bad adress");
//alert("1");
}
else
{
var address1 = document.getElementById("").value;
// alert("Hello");
// alert(document.getElementById(""));
document.getElementById("").value = response;
// alert(response);
map.setCenter(response,13);
// document.getElementById("").value = response;
// svOverlay = new GStreetviewOverlay();
// map.addOverlay(svOverlay); l

var marker = new GMarker(response, {draggable:true});


marker.title = address1;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindow(address1);
});

GEvent.addListener(marker, 'mouseover', function() {
// marker.setImage('blue.png');
});

GEvent.addListener(marker, 'mouseout', function() {
// marker.setImage('pink.png');
});



map.addOverlay(marker);
var addInfo = "Address :
" + address1;

marker.openInfoWindowHtml(addInfo);


}


=> padma (Tuesday 13-May-08 07:34 AM)

    Difference is, you are using Javascript functions and google map APIs for
    geocoding. I am using server side code for geocoding. You can use any
    method. Both should give you same results.
    => Shabdar (Tuesday 13-May-08 02:42 PM)

       Thanks for reply

       => Padma (Wednesday 21-May-08 11:42 PM)
Great Control. But i have very simple question do you know how to draw circle
on the map say around 5 to 10km from the center point. Please help
=> Srikanth (Wednesday 14-May-08 04:29 AM)



Thanks for your Google maps control!
But I want this control in vb.net
can I get it? Ganesh

=> ganesh (Thursday 15-May-08 03:53 AM)

   hi
   shabdar
   i am using your control that works fine but i am facing some problem how
   to remove the point from map after page load happens

   i have this requiremnt
   i am loading all points(lati and long)and displaying in the page load after
   wards i want to show singe point at that time i want to remove all points and
   load to that single point how to remove point from map ?

   thanks and regards
   => seshu (Thursday 15-May-08 05:04 AM)

      You need to remove one by one each GooglePoint from Points property
      of GoogleObject. Something like this,

      GoogleMapForASPNet1.GoogleObject.Points.Remove("P1");

      Here "P1" is ID of pushpin that you have initialized when initializing
      google map.
      => Shabdar (Thursday 15-May-08 09:42 AM)

         hi shabdar

         thanks for your replay thats works fine
         i have one more requirement
         how to increase and decrease the zoom level of map
         => seshu (Thursday 15-May-08 11:56 PM)

             we need to use
              GoogleMapForASPNet1.GoogleMapObject.AutomaticBoundar
              yAndZoom = false;
              => seshu (Saturday 17-May-08 07:58 AM)



   Hi Ganesh,

   You can use both C# and VB.Net code in same web application. Visit
   following link to know how to do it.

   http://www.timheuer.com/blog/archive/2007/02/28/14002.aspx

   Or just Google on element in Web.Config
   => Shabdar (Thursday 15-May-08 10:03 AM)



Thanks for building this wonderful control and for fixing several areas in v1.4.

I would like to use this control over GoogleMaps.Subgurim but I am having
problems in three areas that need to be adressed before I continue, and I'd like
your

help and advice. Issues:
1) Deployment
2) AJAX conflicting with ASP.NET ScripManager
3) Push pin shadows

1) Deployment -- I run VS 2008 / SQL 2005 locally and my ASP.NET 2.0 web
site is a Web Project not Web Site, so I don't have an App_Code folder. Can the

GService.cs and cGoogleMap.cs be compiled by moving into a CODE subfolder
or even being placed in the web site root? I tried this (and change the location in

the ASMX) but although it runs correctly locally, when deployed I get Google
map Ajax errors like it is missing some script. Can the GoogleMapControl be

compiled?

2) Related to #1 above, AJAX is conflicting with ASP.NET ScripManager : I
have a ASP.NET page using a control, one page has the Google Map
Control, and other page(s) have Data Grid displays. I have configured the
ScriptProxyManager as described. The map is AJAX'd (of course) and the the
DataGrid

are also AJAX'd using ASP.NET 2.0 ScriptManager (w/ Ajax extensions). There
are two problems
(a) AJAX works in most cases on my local system, but all non-Google Map
AJAX yields error when deployed (i.e. Like something isn't deployed correctly)
(b) A Linkbutton, used to display either the GoogleMap or dataGrid display,
fails to load the map whenever clicked. I always have to reload the entire

page (this may be a simply logic error - something I obviously missing).

3) Push pin shadows -- This is a rather major annoyance. The control allows the
use of a non-push pin graphic for a marker (i.e. like your car above). BUT,

even as shown in your examples above, the shadow graphic of the push pin
always displays. And more importantly, when a smaller marker is clicked and
the info

box popup is displayed, the point is not at the marker icon, but where the
shadow icon is displayed. The point of display is off 10-20px and appears to be
an

error. Can we turn off the shadow, or make the marker icon and the shadow icon
the same graphic?

Chris
=> Chris mangiapane (Thursday 15-May-08 05:15 PM)



Can the marker shadow icon be turned off or can the marker shadow icon be set
to another graphic?

Chris Mangiapane
=> Chris Mangiapane (Sunday 18-May-08 07:04 PM)



I'm rather new to Ajax. My Google Map does not redraw itself on an Ajax event.

How can I redraw the Google Map on an Ajax event? Is there Ajax event I can
call?
Chris Mangiapane
=> Chris Mangiapane (Sunday 18-May-08 07:09 PM)




   Let me ask in diffenrent way;
   On a ASP.NET AJAX event of a multi-page control, the Google Map does
   not display, unless I do a complete post-back (i.e. page load).

   Can the Google Map be made to redraw itself? Is there a server-side
   method I can call?

   Thanks for you help,
   Chris
   => Chris Mangiapane (Thursday 22-May-08 01:28 PM)

      I couldn't fully understand your problem. But I think this might work
      for you. Go to GoogleMapForASPNet.ascx.cs code behind. And in
      Page_Load event change following lines,

      if (!IsPostBack)
      {
      Session["GOOGLE_MAP_OBJECT"] = GoogleMapObject;
      }
      else
      {
      GoogleMapObject =
      (GoogleObject)Session["GOOGLE_MAP_OBJECT"];

      }

      Change above to,

      if (!IsPostBack)
      {
      Session["GOOGLE_MAP_OBJECT"] = GoogleMapObject;
      }
      else
      {
      GoogleMapObject =
      (GoogleObject)Session["GOOGLE_MAP_OBJECT"];
      if (GoogleMapObject == null)
GoogleMapObject = new GoogleObject();
Session["GOOGLE_MAP_OBJECT"] = GoogleMapObject;

}

What this does is, it creates a new map if it was not initialized properly.
In multipage view, it may not have been initialized properly.
=> Shabdar (Thursday 22-May-08 03:15 PM)

    Thanks very much, I'll give this a try. I think this might do it!

    The map should still be there - I click to MultiView page 2 view
    via AJAX and back to MultiView page 1 (which contains the map)
    via AJAX.
    => Chris Mangiapane (Thursday 22-May-08 05:23 PM)

       Shabdar,

       I really appreciate the efforts, but after applying this change the
       results are the same. The GoogleObject in Session is fine, but
       the map that resides on the 1st page of the MultiView control
       simply displays blank.

       Do you have any other ideas? The only work around that I have
       found is to reload the entire page.

       Chris
       => Chris Mangiapane (Friday 23-May-08 12:34 AM)

           Hi Shabdar, I'm having the same problem. I have the map
           control inside a PopupControlExtender. First time display
           map shows, but if I perform some other unrelated ajax
           action (another popup for instance) and come back to this
           popup, the map doesn't display.

           I'm using 1.5 of of your control which already has the
           above PostBack changes in it. Will keep digging and let
           you know if I find a solution.

           Great control!!! Can't wait for geocoding...:)
           => greg (Saturday 21-Jun-08 08:37 AM)
                     You should keep GoogleMapControl outside of ajax
                     update panel on your ASP.Net page. This way it won't
                     refresh google map.

                     I was not able to solve issue of MultiView control
                     which is reported by Chris Mangiapane.
                     => Shabdar (Monday 23-Jun-08 02:22 PM)




Hai shabdar
i am using your control for my google map requirement thats working fine,
thanks for giving this control
i have small problem but i am unable to solve that problem i went your code
also but no use
problem is i am facing problem
i am replacing default image to my image but i am gettinh shadow of previous
image how i can solve this problem i am in last stage
to release give me some soluation for that

thanks and regards
seshu
=> seshu (Monday 19-May-08 08:03 AM)

   Seshu,

   This control can not replace shadow image. This is a bug. I will release a
   new version for this. For now you can turn off shadow by following way.

   Go to GoogleMapForASPNet.ascx source. Search for following line,

   myIcon_google.image = result.Points[i].IconImage;

   Add following line just after this line,

   myIcon_google.shadow = '';

   There are two instance where you need to do so.
   => Shabdar (Wednesday 21-May-08 09:37 AM)

      Thanks Shabdar, this removes the shadow just fine. Is there a way to
      have the pin popup display to the pin marker, not the now invisible
shadow?

If not, will that also be ddressed in the next release?

Thanks for all your efforts,
Chris
=> Chris Mangiapane (Thursday 22-May-08 01:21 PM)

   Chris,

   You mean when you click on an icon popup is pointing to a place
   which is slightly off from icon. Right?

   This problem is not because of code. It's because of icon image. If
   you use default google icons, it will work just fine. You need to
   have your icon pointing to right place. In my samples, I am also
   using a little offset icons. That's how popup is slightly off from
   image.
   => Shabdar (Thursday 22-May-08 03:02 PM)

       Yes that's exactly what I mean.

       I am using a 10px x 10px icon, somewhat smaller than the
       standard Google icons. I could have 100s of icon to place on a
       map, so I need a much smaller icon. So are you saying I have to
       either use a large icon, or what?
       => Chris Mangiapane (Thursday 22-May-08 03:13 PM)

            I don't think it's a problem with the icon size. I don't have
            perfect explanation. But in my experiments I have found
            that if you design your icon in such a way that your icon's
            pointing area(edge) is on Bottom center part of your image
            then it will be a perfect icon. For sample image, type
            following URL in your browser and you will see an image
            explaining this.

            shabdar_images/icon_guide.jpg
            => Shabdar (Thursday 22-May-08 03:29 PM)

               Sorry, I am not following you.
If I add one point onto a map with my 10x10 small
green icon, and a second point with the 'standard' pin w/
shadow icon, and each has a unique geocode and a
popup assigned. I assert only the second popup will
display properly on it's geo-coordinates. The smaller
icon's popup will display 15-30 pixels(guessing) to the
bottom/right way off the icon.

When there are several icons in confined area, it looks
like the popup is for another icon -- not good UI (I know
you understand).

Doesn't your code control the 'point' of the popup?
=> Chris Mangiapane (Thursday 22-May-08 05:37
PM)

   Ok I think you are using transparent image(maybe
   PNG?) which has wider canvas width then it
   displays. Try opening it with some photo editor and
   reduce canvas size so that it fits your image.
   => Shabdar (Friday 23-May-08 10:29 AM)

      This image I am 5px X 5px JPG file - no
      transparent image with wider cavas. Any other
      thoughts?
      => Chris Mangiapane (Thursday 29-May-08
      01:52 PM)

          Try setting IconImageHeight and
          IconImageWidth properties of GooglePoint
          object to 5. See if it works. Make sure you
          set them after specifying image.

          Example,

          GP1.IconImage = "icons/RedCar.png";
          GP1.IconImageHeight = 5;
          GP1.IconImageWidth = 5;
          => Shabdar (Thursday 29-May-08 02:29
          PM)
I had this code in place: I tried not only
GP1.IconImageHeight = 5;
GP1.IconImageWidth = 5;
but also
GP1.IconImageHeight = 10;
GP1.IconImageWidth = 10;
and
GP1.IconImageHeight = 25;
GP1.IconImageWidth = 25;

Increasing the icon image size makes the
image larger as expected, but the popup
HTML always displays in the same spot
regardless of image size, oughly 30px
below the icon image.
=> Chris Mangiapane (Thursday 29-
May-08 03:18 PM)

   Looks like the shadow image has a
   fixed size, and the popup location is
   associated with with the shadow
   size. Is there a property that I can set
   the 'shadowSize' to like the
   iconSize?
   => Chris Mangiapane (Thursday
   29-May-08 03:28 PM)

       Ok, go to line where you have
       added following code,

       myIcon_google.shadow = '';

       Just after this line add follwing
       code,

       myIcon_google.shadowSize =
       new GSize(0, 0);

       You can also try setting
shadowSize to (5,5)
=> Shabdar (Thursday 29-May-
08 04:04 PM)

  Tried both:
  myIcon_google.shadowSize
  = new GSize(0, 0);
  myIcon_google.shadowSize
  = new GSize(5, 5);
  Same result, same errant
  location. Feels like the
  location is hard coded
  somewhere...
  => Chris Mangiapane
  (Thursday 29-May-08 04:28
  PM)

     Checkout this tutorial for
     custom markers. It tells
     you exactly what you are
     looking for.

     http://econym.googlepag
     es.com/custom.htm

     # iconAnchor : without it
     your marker won't
     appear in the correct
     place
     # infoWindowAnchor :
     without it
     marker.openInfoWindow
     () will fail
     => Shabdar (Friday 30-
     May-08 09:24 AM)

        Thank You Shabdar!

        The iconAnchor did
the trick!
myIcon_google.icon
Anchor = new
GPoint(2, 10);

Now the popup
displays correctly on
my 10px by 10px
icon image.
=> Chris
Mangiapane (Friday
30-May-08 10:34
AM)


   Hi!
   Thanks for this
   control.

   There is a way to
   handle (server-
   side) a click
   event on a
   marker or on the
   map in general?

   tnx a lot.
   CM
   => CM (Monday
   19-May-08
   08:27 AM)



   Thank you for
   doing this, much
   appreciated!
   What would it
   take to add
   javascript to
   create a
mouseover effect
for the info
window (instead
of click)? See
www.trulia.com
for an example
of this.
=> Douglas
Kennedy
(Monday 19-
May-08 03:43
PM)

   Go to source
   of
   GoogleMapF
   orASPNet.asc
   x. Search for
   "CreateMarke
   r" function. In
   this function
   replace this
   code

   GEvent.addLi
   stener(marker
   , "click",
   function() {
   map.openInfo
   WindowHtml
   (point,InfoHT
   ML); });

   with
   following
   code

   GEvent.addLi
   stener(marker
,
"mouseover",
function() {
map.openInfo
WindowHtml
(point,InfoHT
ML); });

If you want to
keep both
events (click
and
mouseover),
add above
line instead of
replacing.
=> Shabdar
(Wednesday
21-May-08
09:23
Thanks very
much again.
While your
suggestion
above works,
I want a fast
tooltip that is
separate from
the
infoHTML.
Here's what I
tried. I get no
javascript
errors, but the
tooltip doesn't
show up. I'm
sure you can
find my error
in a second.
1.)
Page.ClientSc
ript.RegisterS
tartupScript(P
age.GetType(
),
"onLoadCall"
, " if
(window.Dra
wGoogleMap
){
DrawGoogle
Map(); var
tooltip =
document.cre
ateElement("d
iv");
document.get
ElementById(
"GoogleMap_
Div").append
Child(tooltip)
;
tooltip.style.v
isibility="hid
den"; } ");
2.)In
CreateMarker
function, add
the following:
marker.tooltip
='
'+sTitle+'
';
GEvent.addLi
stener(marker
,"mouseover",
function()
{
showTooltip(
marker);
});
GEvent.addLi
stener(marker
,"mouseout",
function()
{
tooltip.style.v
isibility="hid
den";
});
3.)Add
function
showtooltip:
function
showTooltip(
marker)
{
tooltip.innerH
TML =
marker.tooltip
;
var
point=map.ge
tCurrentMap
Type().getPro
jection().from
LatLngToPix
el(map.getBo
unds().getSou
thWest(),map.
getZoom());
var
offset=map.g
etCurrentMap
Type().getPro
jection().from
LatLngToPix
el(marker.get
Point(),map.g
etZoom());
var
anchor=mark
er.getIcon().ic
onAnchor;
var
width=marker
.getIcon().ico
nSize.width;
var pos = new
GControlPosi
tion(G_ANC
HOR_BOTT
OM_LEFT,
new
GSize(offset.
x - point.x -
anchor.x +
width,-
offset.y +
point.y +
anchor.y));
pos.apply(tool
tip);
tooltip.style.v
isibility="visi
ble";

Only answer
if it's an easy
fix,
Thanks, Doug
=> Doug
(Thursday
22-May-08
01:48 AM)
AM)

								
To top