![Untitled-1.gif]()
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.
- Allows you to draw polylines and polygons
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.
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.
![Untitled-2.gif]()
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.
![Untitled-3.gif]()
- 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).
![Untitled-4.gif]()
- Go to your web.config file and add following lines between <System.Web></System.Web> element.
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.
![Untitled-5.gif]()
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.
![Untitled-6.gif]()
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 can add as many pushpins as you wish. Now run website again and you should see pushpins on map.
![Untitled-7.gif]()
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";
![Untitled-8.gif]()
- You can format InfoHTML property using standard HTML tags.
example: GP.InfoHTML = "This is <font color='red'><b>Pushpin-1</b></font>";
![Untitled-9.gif]()
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.
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.
![Untitled-10.gif]()
- Move your button inside this update panel.
![Untitled-11.gif]()
- 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
![Untitled-12.gif]()
Create points for polyline
Add Polyline to Google Map control,
Creating Polygons with Google Map control
![Untitled-13.gif]()
Create points for polyline,
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 will explain you souce code of Google Map user control and how to customize it for your own use.