ThinkGeo.com    |     Documentation    |     Premium Support

Googlemaps Overlay

Hello,


I have tryed some examples about how to use googlemap and I'm having some troubles, I can see the map and I can load a bitmap and a label representing a vehicle over the google map, the problem that I have is that sometimes when I'm zooming in/out, or when I'm moving around the map, it gives me error "403", and another times show error "500" . Do you have any idea about what I'm doing wrong?  I can't figure out how can I catch these exeption when it occurs. Here is an example of the code that I'm using:



 



double Longitude = -58.33806539154050;double Latitude = -34.65402830688480;


 


 


 


double xG = 6378137.0 * Math.PI / 180 * Longitude;

 


 


double yG = 6378137.0 * Math.Log(Math.Tan(Math.PI / 180 * (45 + Latitude / 2.0)));

 


winformsMap1.BackgroundOverlay.BackgroundBrush =


new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));

winformsMap1.CurrentExtent =


winformsMap1.MapUnit =


 


new RectangleShape(( xG - 2300), (yG + 1200), (xG + 2300), (yG - 1200));GeographyUnit.Meter;//Adds the Google Map as an overlay

 


GoogleMapsOverlay google = new GoogleMapsOverlay("Google Map");

google.MapType =


google.CacheDirectory =


winformsMap1.Overlays.Add(


 


 


GoogleMapsMapType.RoadMap;@"C:\GoogleCache";"GoogleOverlay", google);//// This sets the zoom levels to map to Googles. We next make sure we snap to the zoomlevels

winformsMap1.ZoomLevelSet =


winformsMap1.ZoomToScale(winformsMap1.ZoomLevelSet.ZoomLevel15.Scale);


new GoogleMapZoomLevelSet();

 


LayerOverlay layerOverlay = new LayerOverlay();

 


pointLayer.Open();


pointLayer.Columns.Add(


pointLayer.Close();


 


InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer();new FeatureSourceColumn("Text"));//Sets the projection parameters to go from Geodetic (EPSG 4326) or decimal degrees to Google Map projection (Spherical Mercator).

 


 


proj4.InternalProjectionParametersString =


proj4.ExternalProjectionParametersString =


 


Proj4Projection proj4 = new Proj4Projection();Proj4Projection.GetEpsgParametersString(4326);Proj4Projection.GetGoogleMapParametersString();//Applies the projection to the InMemoryFeatureLayer so that the point in decimal degrees (Longitude/Latitude) can be 

 


//match the projection of Google Map.

pointLayer.FeatureSource.Projection = proj4;



 


//Creates the feature made of a PointShape with the Longitude and Latitude values.

 


 


Feature GPSFeature = new Feature(new PointShape(Longitude,Latitude));//Format the Longitude and Latitude into a nice string as Degrees Minutes and Seconds

 


string LongLat = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(GPSFeature);

 


//Sets the InMemoryFeatureLayer to have it displayed with Square symbol and with text.

GPSFeature.ColumnValues.Add(


pointLayer.InternalFeatures.Add(


"Text", LongLat);"GPS",GPSFeature);

pointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle =


 


pointLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle =


 


pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel =


PointStyles.CreateSimplePointStyle(PointSymbolType.Square,GeoColor.StandardColors.Red, GeoColor.StandardColors.Black, 2, 12);TextStyles.CreateSimpleTextStyle("Text", "Arial", 12, DrawingFontStyles.Bold,GeoColor.StandardColors.Black, GeoColor.StandardColors.White, 3, -10, 10);ApplyUntilZoomLevel.Level20;

 Overlay.Layers.Add(pointLayer);

winformsMap1.Overlays.Add(layerOverlay);



winformsMap1.Refresh();



Best Reagrds,





Your code is a little bit difficult to read because it seems that some lines have jumped unexpectingly and in different order. 
  One thing caught my attention, though. What are you doing in the following lines? 
  
 double xG = 6378137.0 * Math.PI / 180 * Longitude;  
 double yG = 6378137.0 * Math.Log(Math.Tan(Math.PI / 180 * (45 + Latitude / 2.0)));  
  
  It seems to me that you are doing your own math for projection. Could you explain what you are doing exactely here and why you are not using the Proj4Projection class in that case? Also, it would help to have that code in a little sample ap to see the problem happening. Thank you.

Hello,


Sorry for the bad paste. Atached is copy of the code, the math that we are using is becouse we couldn't use the Proj4Projection on the rectangleShape and using this simple math we could convert decimal degrees to google projection.


Please try the code and let me know if it works fine, some times it work with no errors an then it gives errors all the time and like I said before I don't know how to fix it.


 


Best Regards,


 


Leandro



1807-Form1.cs (3.56 KB)

Thank you the attached file. Now I understand much better what is going on. I will test that out tomorow morning and let you know my findings. 
 Thank you.

 Sorry for the delay in responding. I looked at your code and although I don't understand everything in your code, it seems to me that your goal is to display on Google Map a GPS point (in Long/Lat) and have the map centered to it. I suggest you check the Code Community project GPS to Google Map which accomplishes, in a more straightforward way, I think, the same goal.


code.thinkgeo.com/projects/show/gpstogooglemap


 



Hello Val, 
  
 I’ve already seen the gps to google project, but I’m using desktop edition and I’m not sure if it work with it. But anyway I was able to show a bitmap over the googlemap, but my only problem is that googlemap gives error #500 and #403 all the time and I can’t catch them. 
  
 Regards, 
  
 Leandro

Ok, we will publish the Desktop edition of GPS to Google Map. I will let you know as soon as it is up in the Code Community.



 I let you know that today we publish the Desktop version of GPS to Google Map in the Code Community. You can check it out.


code.thinkgeo.com/projects/s...gledesktop