ThinkGeo.com    |     Documentation    |     Premium Support

GoogleMapsOverlay or GoogleMapsLayer information

I need some kind of straight forward explanation on how to implement one of the Google maps features. I can’t seem to find the correct ClientID and PrivateKey combination, and can’t seem to find the correct one. On top of that, I can’t seem to get it to tell me what request it is sending as the SendingWebRequest never fires. What I am doing is below, but it doesn’t work. It just throws a “One or more errors occurred” exception.

var googleOverlay = new GoogleMapsOverlay(@"C:\temp\GoogleCache", clientId, privateKey);
googleOverlay.TileType = TileType.MultipleTile;
googleOverlay.DrawingException += this.overlay_DrawingException;
googleOverlay.IsVisible = false;
googleOverlay.SendingWebRequest += googleOverlay_SendingWebRequest;
googleOverlay.SentWebRequest += googleOverlay_SentWebRequest;
this.map.Overlays.Insert(0, "GOOGLE", googleOverlay);

This shouldn’t be that complicated, but I’m at a loss.

What I need to know are:

  1. Where to find the client id on Google’s API Manager and which specific one I need to create.
  2. Where to find the private key on Google’s API Manager and which specific one I need to create
  3. Why the SendingWebRequest and SetnWebRequest events aren’t firing.

Hi Clay,

Please check the response below.

1. Where to find the client id on Google’s API Manager and which specific one I need to create.
We can get the client id from the Google enterprise supports.

2. Where to find the private key on Google’s API Manager and which specific one I need to create
We can get the private key from the Google enterprise supports.

3. Why the SendingWebRequest and SetnWebRequest events aren’t firing.
The reason is that the googleOverlay is invisible. Please changing the IsVisible property of GoogleOverlay as following:

googleOverlay.IsVisible = true;

Thanks,
Peter

I know where I can get the client ID and private key, but I don’t know which one to get. That’s why I asked for the specific one I need to create.

The IsVisible property is changed further down in the code.

I did change my code to use the GoogleMapsOverlay with no constructor and it tries to load some, but then I begin to receive an error which states “No Imaging component suitable to complete this operation was found.”

Hi Clay,

For Google map, we require static key, because in WPF edition we get tile from Google static API.

I am not sure why you get the exception, because I tested with the code as below and it works well, please make sure you are using our latest dll.

GoogleMapsOverlay googleOverlay = new GoogleMapsOverlay();
googleOverlay.TileType = TileType.MultipleTile;
googleOverlay.IsVisible = true;
googleOverlay.SendingWebRequest += googleOverlay_SendingWebRequest;
Map1.Overlays.Insert(0, “GOOGLE”, googleOverlay);

Regards,

Don

@Clay

The “No Imaging component …” problem is a well know bug in ThinkGeo, most recently here: GoogleMapsOverlay: No imaging component suitable to complete this operation was found

If you have not entered the correct key/ids then for me it happens all the time.

We have tried to get id/key from Google but so far no luck.

Another suggestion is to use Bing, they are much easier to work with, only 1 key.
However the BingOverlay from ThinkGeo still has some minor issues, but it works better then the GoogleOverlay in my oppinion.

Btw I am not from ThinkGeo, the new forum does not easily let you see who is an admin.

/Morten

Hi Morten,

Thanks for your share, I think your reply is very helpful! Because I don’t have a really Google key for test, so that’s maybe why I cannot reproduce this exception.

We are glad to see our users share their experience in our forum, so whether comes from ThinkGeo is not important here.

Regards,

Don

@Don

As I wrote above the exception happens when you do NOT have a key.

/Morten

@Morten1

Oh, I misunderstand that, I thought you means this exception thrown when you type in incorrect key.

But that’s strange, I cannot reproduce that local without the key.

I think maybe I missed something else about it.

I will do more test about this.

Regards,

Don

@Don

Were you ever able to resolve/reproduce this? I’m running into the same error (“No imaging component…”) when I attempt to use the GoogleMapsOverlay in the WPF version of ThinkGeo. I’ve added a SendingWebRequest handler which creates a webrequest and attaches my key, but I’m still getting the same error. Furthermore, I can see, using Google’s API dashboard, that my key is generating requests, so I don’t believe the problem is with my key or authentication on Google’s end.

Any chance you have a further solution to this problem?

Thanks,
Ian

Code:

private void m_Map_Loaded(object sender, RoutedEventArgs e)
{
  m_Map.MapUnit = GeographyUnit.Meter;
  m_Map.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));
  GoogleMapsOverlay googleOverlay = new GoogleMapsOverlay();
  googleOverlay.SendingWebRequest += googleOverlay_SendingWebRequest;
  googleOverlay.MapType = GoogleMapsMapType.Terrain;
  googleOverlay.IsVisible = true;
  m_Map.Overlays.Add(googleOverlay);
  m_Map.ZoomLevelSet = new GoogleMapsZoomLevelSet();

  InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer();

  //Sets the projection parameters to go from Geodetic (EPSG 4326) or decimal degrees to Google Map projection (Spherical Mercator).
  Proj4Projection proj4 = new Proj4Projection();
  proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
  proj4.ExternalProjectionParametersString = 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;

  //Values in Longitude and Latitude.
  double Longitude = -77.0369;
  double Latitude = 38.9072;

  //Sets the extend of the map based on the GPS point.
  proj4.Open();
  Vertex projVertex = proj4.ConvertToExternalProjection(Longitude, Latitude);
  proj4.Close();

  double extendWidth = 2300;
  double extendHeight = 1200;

  m_Map.CurrentExtent = new RectangleShape((projVertex.X - extendWidth), (projVertex.Y + extendHeight),
      (projVertex.X + extendWidth), (projVertex.Y - extendHeight));

  m_Map.Refresh();
}

void googleOverlay_SendingWebRequest(object sender, SendingWebRequestEventArgs e)
{
  e.WebRequest = WebRequest.Create(e.WebRequest.RequestUri + "&key=123456789etc");
}

Hi Ian_Cyr,

I think you can do further test based on your code.

  1. Remove unnecessary code like your pointLayer , only render the GoogleOverlay
  2. Switch the googleOverlay.MapType to do more test
  3. In Sending request, get the request URL, directly view the URL in browser and see what’s the result. If it can rendered in browser, it should be works in your map

And please hide your key in code in this post.

Regards,

Don

@Don -

Based on your suggestions, I’m now using the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WpfDesktopEdition;

namespace MyProject
{
  /// <summary>
  /// Interaction logic for MapDisplay.xaml
  /// </summary>
  public partial class MapWindow : Window
  {
    public MapWindow()
    {
      InitializeComponent();
    }

    private void m_Map_Loaded(object sender, RoutedEventArgs e)
    {
      m_Map.MapUnit = GeographyUnit.Meter;
      m_Map.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

      GoogleMapsOverlay googleOverlay = new GoogleMapsOverlay();
      googleOverlay.SendingWebRequest += googleOverlay_SendingWebRequest;
      googleOverlay.MapType = GoogleMapsMapType.Terrain;
      googleOverlay.IsVisible = true;
      m_Map.Overlays.Add(googleOverlay);
      m_Map.ZoomLevelSet = new GoogleMapsZoomLevelSet();

      m_Map.Refresh();
    }

    void googleOverlay_SendingWebRequest(object sender, SendingWebRequestEventArgs e)
    {
      e.WebRequest = WebRequest.Create(e.WebRequest.RequestUri + "&key=mYhIdDeNkEy");
    }
  }
} 

For completeness sake, my .xaml is as follows:

<Window x:Class="MyProject.MapWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:uc1="clr namespace:ThinkGeo.MapSuite.WpfDesktopEdition;assembly=WpfDesktopEdition"
        Title="MapWindow" Height="900" Width="900">
  <Grid>
    <uc1:WpfMap Name="m_Map" Loaded="m_Map_Loaded"/>
  </Grid>
</Window>

I’m still running into the same error. I’ve viewed a few of the URLs in my browser, and they appear to resolve fine, but the error is very consistent when running my project. The base code is copied directly from your GPS to Google Map (Desktop) Code Sample. The error seems to occur when zooming in - zooming out hasn’t seen any crashes, although I do get unrendered map pieces quite often, which I wonder if it is a symptom of some underlying problem.

Edit: In addition, I’ve tried the code with all of the different GoogleMapsMapType options (Hybrid, Mobile, Satellite, Terrain, RoadMap), and they all throw the same error.

Thanks,
Ian

Hi Ian,

Thanks for your update, it looks your test code is simple enough and you mentioned the requested url render correct.

So I think you can check some other things,

  1. Directly run our samples, which you can get from our wiki or product center, please see whether the exception will be thrown when you run our sample.

  2. Use GoogleMapsLayer instead of GoogleMapsOverlay, see whether that works.

  3. Let me know your detail dll version.

Regards,

Don

@Don-

  1. Unfortunately, I can’t directly run your sample for this code. The sample I’m emulating is the GPS to Google Map (Desktop), which is built in the Desktop Edition of ThinkGeo. Unfortuantely I only have a license for the WPF version of the product, so I can’t run the project directly. If you know of a way around this, I’d be happy to try and run the code directly.

  2. I’ll look into the Layer instead of the Overlay - if you have any tips on how to get it running, they’d be appreciated.

Edit: It appears that in order to use a GoogleMapLayer, we need a clientID and PrivateKey. From what I can find in Google’s API documentation, these options are only available to those who have the Premium Plan, which I currently don’t have, nor was I planning on having access to. So at this point in time, I’m not sure how to transition from the Overlay to the Layer. Any advice would be greatly appreciated.

  1. I’m currently running Daily Full Production 9.0.0.484.

Thanks,
Ian

Hi Ian,

  1. You can eval our desktop edition. Or you don’t need open this sample, you can open WPFEdition HowDoISamples project, then find a sample which contains GoogleOverlay or GoolgeLayers, and run that.

  2. If you don’t have the clientid and prvaitekey for now, please just ignore this suggestion.

  3. Please try to use DevelopementEdition 9.0.x.0, because the development contains much more enhancement thant 9.0.0.x version.

Regards,

Don

@Don-

  1. I’ll try evaling the desktop edition. The WPF How Do I Samples project doesnt’ seem to contain any references to Google when I search - if I’ve missed a reference that you know of, please let me know so I can try and run it.

Edit: Activated the trial of the Desktop Edition. The following is the modified code, taken from the sample and modified to match the code I’ve been running in the WPF version as closely as possible.

using System;
using System.Windows.Forms;
using System.Net;
using System.Collections.ObjectModel;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.DesktopEdition;


namespace  GPStoGoogleMapDesktop
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void TestForm_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.Meter;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

            GoogleMapsOverlay googleOverlay = new GoogleMapsOverlay();
            googleOverlay.SendingWebRequest += googleOverlay_SendingWebRequest;
            googleOverlay.MapType = GoogleMapsMapType.Hybrid;
            googleOverlay.IsVisible = true;
            winformsMap1.Overlays.Add(googleOverlay);

            // This sets the zoom levels to map to Googles.  We next make sure we snap to the zoomlevels
            winformsMap1.ZoomLevelSet = new GoogleMapsZoomLevelSet();

            winformsMap1.Refresh();
        }

        void googleOverlay_SendingWebRequest(object sender, SendingWebRequestEventArgs e)
        {
           e.WebRequest = WebRequest.Create(e.WebRequest.RequestUri + "&key=MyHiDdEnKeY");
        }
    }
}

The above code doesn’t seem to have any issues, despite being pretty much exactly the same.

  1. For internal development purposes, we’re currently locked into Daily Full Production 9.0.0.484. I’ll contact my team and see if we can migrate, but I’m not sure that’s an option at this point in time.

Thanks,
Ian

Hi Ian,

I am not sure where is the problem, if the code looks the same but the result is different, please try to build a new project, and reference the dlls then test with the code again.

For what’s the different, maybe you want to compare something like referenced dll, used .net framework version etc.

Regards,

Don