|
|
Google Maps Control for ASP.Net - Part 1
Free Open source Control

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.
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 <System.Web></System.Web>
element.
<httpHandlers>
<remove path="*.asmx" verb="*"/>
<add path="*.asmx" verb="*"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35"
validate="false"/>
<add path="*_AppService.axd" verb="*"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35"
validate="false"/>
<add path="ScriptResource.axd" verb="GET,HEAD"
type="System.Web.Handlers.ScriptResourceHandler,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35"
validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule"
type="System.Web.Handlers.ScriptModule,
System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
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 = "<YourGoogleMapKey>";
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 <font color='red'><b>Pushpin-1</b></font>";
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.
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,
GooglePoint GP1 = new GooglePoint();
GP1.ID = "GP1";
GP1.Latitude = 43.65669;
GP1.Longitude = -79.44268;
GP1.InfoHTML = "This is point 1";
GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP1);
GooglePoint GP2 = new GooglePoint();
GP2.ID = "GP2";
GP2.Latitude = 43.66619;
GP2.Longitude = -79.44268;
GP2.InfoHTML = "This is point 2";
GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP2);
GooglePoint GP3 = new GooglePoint();
GP3.ID = "GP3";
GP3.Latitude = 43.67689;
GP3.Longitude = -79.43270;
GP3.InfoHTML = "This is point 3";
GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP3);
- Create polyline between points GP1, GP2 and GP3
//Define polyline
GooglePolyline PL1 = new GooglePolyline();
PL1.ID = "PL1";
//Give Hex code for line color
PL1.ColorCode = "#0000FF";
//Specify width for line
PL1.Width = 5;
//Add points
PL1.Points.Add(GP1);
PL1.Points.Add(GP2);
PL1.Points.Add(GP3);
- Add Polyline to Google Map control,
GoogleMapForASPNet1.GoogleMapObject.Polylines.Add(PL1);
Creating Polygons 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 polygon using above points,
//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 polygon to google map control,
GoogleMapForASPNet1.GoogleMapObject.Polygons.Add(PG1);
Traffic Overlays
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.
Special Notes
I have published this article on codeproject.com as well. Here is the link to this article.
http://www.codeproject.com/KB/webforms/Google-Maps-User-Control.aspx
Comments/Questions
Add New Comment/Question
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 | | Reply | | Yes I am trying to include all functionalities that current Google APIs provide. But I can not tell you when. | Shabdar | | Reply | |
| 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 | | Reply | | 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 | | Reply | |
| 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 | | Reply | 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 -> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
(2) Or go to GoogleMapForASPNet.ascx source and change <div id="GoogleMap_Div" style="width:<%=GoogleMapObject.Width %>;height:<%=GoogleMapObject.Height %>;"> to <div id="GoogleMap_Div" style="width:<%=GoogleMapObject.Width %>;height:<%=GoogleMapObject.Height %>;position:relative;">
(3)Set control container (DIV) to fixed width and height. Then apply percentage width and height to control.
| Shabdar | | Reply | |
| 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 | | Reply | 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 | | Reply | 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 | | Reply | |
|
| 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 | | Reply | 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 | | Reply | |
| 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 | | Reply | | 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 | | Reply | | | have you any plans to add GInfoWindowTab ? | JG | | Reply | | Hi
GoogleMapForASPNet1.GoogleMapObject.MapType= "G_SATELLITE_MAP"
I nide to change the default map type to Satallite Map
Please help me
Great | Zayati | | Reply | You need to do it like this,
GoogleMapForASPNet1.GoogleMapObject.MapType= GoogleMapType.SATELLITE_MAP;
GoogleMapType is a sealed class defined in cGoogleMap.cs file. | Shabdar | | Reply | |
| | I'd like to use the control in my VB.Net site. So you have a VB sample? Thanks, Chad | Chad Hanson | | Reply | | 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:
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>
<uc1:GoogleMapForASPNet ID="GoogleMapForASPNet1" runat="server"/>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
Only a part of the map gets displayed and it is miscentered. | legcsabi | | Reply | 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,
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell WIDTH=500px HEIGHT=500px>
<uc1:GoogleMapForASPNet ID="GoogleMapForASPNet1" runat="server"/>
</asp:TableCell>
</asp:TableRow>
</asp:Table> | Shabdar | | Reply | 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 | | Reply | 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 | | Reply | |
|
|
| 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 | | Reply | | Yes, I will be writing implementation details very soon so that you can customize it for your needs. | Shabdar | | Reply | | i need good ducumantion for presentation of google map coding | hitesh | | Reply | |
|
| 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 | | Reply | 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 | | Reply | |
| 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 | | Reply | 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 | | Reply | |
| 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 | | Reply | 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 | | Reply | |
| | hi,how to find distance between two points on map | Revathi | | Reply | 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 | | Reply | Example usage of this class,
int distance = CDistanceBetweenLocations.Calc(28.33,-78.55,34.2,-82.11) | Shabdar | | Reply | 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 | | Reply | |
|
|
| 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 | | Reply | 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 | | Reply | | 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 | | Reply | |
| 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 | | Reply | | Thanks Darren for adding extra functionality to this control. I will consider adding these properties in next release. | Shabdar | | Reply | | 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 | | Reply | |
|
| 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 | | Reply | | 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 | | Reply | 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 <ScriptManagerProxy> inside control, which allows you to insert <ScriptManager> on page.
Go to GoogleMapControl.aspx source and replace following code,
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/GService.asmx" />
<asp:ServiceReference Path="~/GoogleMapForASPNet.ascx" />
</Services>
</asp:ScriptManager>
with
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Services>
<asp:ServiceReference Path="~/UserControls/GService.asmx" />
</Services>
</asp:ScriptManagerProxy>
After doing this you can insert <ScriptManager> object at the start of your page. | Shabdar | | Reply | 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:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Services>
<asp:ServiceReference Path="~/GService.asmx" />
<asp:ServiceReference Path="~/GoogleMapForASPNet.ascx" />
</Services>
</asp:ScriptManagerProxy>
Thanks again for your help | Brian | | Reply | 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 | | Reply | |
|
|
| 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 | | Reply | 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 | | Reply | i need to google map calculate between two location .
if u have any sample for that plz send me ..
waiting for response...
Hitesh | Hitesh | | Reply | Did you mean calculate distance between two locations?
I have provided class for that. See my reply for Revathi above. | Shabdar | | Reply | |
|
|
| 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 | | Reply | | 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 | | Reply | 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,
http://shabdar.org/downloads/GoogleMapControl_VS2008.zip
Copy paste above link in your browser address bar to download.
| Shabdar | | Reply | 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 | | Reply | 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 | | Reply | 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 | | Reply | | I don't have any solution now, but will take a look and respond if I get anything. | Shabdar | | Reply | 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 | | Reply | 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 <script></script> (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 | | Reply | I kind of solved it. After some trial and error I have deleted:
<asp:ServiceReference Path="~/GoogleMapForASPNet.ascx" /> 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 | | Reply | | 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 | | Reply | |
|
|
|
|
|
|
|
|
| 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 | | Reply | 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=================================================
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions"
type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting"
type="System.Web.Configuration.ScriptingSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler"
type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices"
type="System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization"
type="System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService"
type="System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />
<section name="authenticationService"
type="System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
Add following section outside <system.web> section.
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a
custom converter -->
<jsonSerialization maxJsonLength="500000">
<converters>
<!--<add name="ConvertMe"
type="Acme.SubAcme.ConvertMeTypeConverter"/>-->
</converters>
</jsonSerialization>
<!-- Uncomment this line to enable the authentication service.
Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<!-- Uncomment these lines to enable the profile service. To
allow profile properties to be retrieved
and modified in ASP.NET AJAX applications, you need to add
each property name to the readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true"
enableCaching="true" />
-->
</scripting>
</system.web.extensions>
</configuration> | Shabdar | | Reply | |
| | Did you by any chance make a Google Chart Wrapper too? :) | Alex | | Reply | | 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 | | Reply | | 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 | | Reply | | 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 | | Reply | 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.GetStringV |
|
|