ThinkGeo.com    |     Documentation    |     Premium Support

Google overlay auto load map issue

Hi Team,

We have been using ThinkGeo Google Overlay for some time with multi tile configuration as single tile is not covering whole screen for our tablet. we have couple of questions as below.

  1. Is there a way to set height and width for single tile using google overlay
  2. when we are performing CenterAt method, map is not loading on its own until we tap on screen or perform some action (In multi-tile).

Hi Patrick,

I’ll be glad to help out. Regarding your first question, the GoogleMapsOverlay only supports SingleTile mode. And when we request a tile from Google, they will return a tile based on your account. I believe a basic account is limited to 640x640. And if you have a premium account it may go as high as 2048x2048. Our overlay just renders that image on your canvas. If a 640x640 tile is returned from Google and the map size is larger than that, it just centers what was returned.

Regarding your 2nd question, how did you set up the map to show the GoogleMapsOverlay in multi-tile? Do you have some sample code or a .sln you can attach?

Thanks,
John

Hi John,
Thanks for providing information.
We are using GoogleMapsLayer and adding it to overlay which is allowing multi Tile.

mapView.ZoomLevelSet = new SphericalMercatorZoomLevelSet();
GoogleMapsLayer layer = new GoogleMapsLayer(AppConstants.GoogleMapApiKey, “”);
layer.PictureFormat = GoogleMapsPictureFormat.Jpeg;
layer.MapType = MapUtilities.GetSelectedMapType(layerType);

            layer.DrawingExceptionMode = DrawingExceptionMode.DrawException;
            layer.DrawingException += Layer_DrawingException;

            LayerOverlay layerOverlay = new LayerOverlay();
            layerOverlay.TileType = TileType.MultiTile;
            layerOverlay.DrawingQuality = DrawingQuality.HighSpeed;
            layerOverlay.Layers.Add(layer);

Hi John,
After changing the tiletype from multi tile to single tile… Map is working fine as expected but since I have been using the app in landscape mode in my tablet, map is showing in square shape instead of rectangle.
Do we have any option to fit the map in full screen?
or
Can we customize tile width and height?

Hi Patrick,

Yes, I think we have a few options for positioning that single tile better. I can work to build a quick sample, but to speed up the process, I want to make sure I’m using the same overlay/layers. Can you attach a simple .sln to this ticket that shows the issue? Or at least the code of you initializing the layer and overlay? And also, can you confirm if you’re on the free, standard or premium tier plans with the google maps static api?

Thansk,
John

Hi John,
We are using Standard plan and below is google layer and overlay initializing code.

mapView.ZoomLevelSet = new SphericalMercatorZoomLevelSet();
GoogleMapsLayer layer = new GoogleMapsLayer(AppConstants.GoogleMapApiKey);
layer.PictureFormat = GoogleMapsPictureFormat.Jpeg;
layer.MapType = GoogleMapsMapType.Hybrid;
layer.DrawingExceptionMode = DrawingExceptionMode.DrawException;

            LayerOverlay layerOverlay = new LayerOverlay();
            layerOverlay.TileType = TileType.SingleTile;
            layerOverlay.DrawingQuality = DrawingQuality.HighSpeed;
            layerOverlay.Layers.Add(layer);
            mapView.Overlays.Add(MapViewConstants.BACKGROUND_OVERLAY, layerOverlay);

Hi Patrick,

I assume you’re on the basic subscription level for Google Maps Api? This limits your tile size to 640 x 640. If you were to upgrade to the premium I believe you can go as high as 2048 x 2048 which would fix the issue.

To clarify what’s occurring in your screenshot, the ThinkGeo GoogleMapsLayer makes a request to google using the width and height of your map canvas. So, in my testing, my phone requests a tile that’s 540x828 using this url:

If you put that request in your browser and put in your correct api key you’ll see that google returns an image that’s 540x640 due to the 640x640 limitation. If you were on the premium plan, google would return an image that’s 540x828 and there would be no white space to the left or right of the map.

Thanks,
John

Hi John,
Thanks for providing the information. we have contacted google team and we have been resolved map size issue.
I have debugged the code and observed scale=2 in web request url.
Do we have any option to override scale value from 2 to 1?

Hi Patrick,

There’s no property to set the scale. The GoogleMapsLayer calculates this value based on several factors like the canvas, screen size, zoomlevel, etc.

I’m curious though, is there a scenario where the scale is incorrect? Or why do you want to request with a different scale?

Thanks,
John

Hi John,
In web request url, we observed the screen size along with scale value. Due to adding scale=2 we are getting double pixels than whatever we requested. example: if we requested 640x640 in size then we will get 1280x1280.
We have an option like Autopan. Whenever current location has changed, we have been setting the current location in center of the map by using CenterAt(currentPosition) method.
Here we are getting continuous coordinates into system so our logic is continuously setting that position to center which is causing performance issue. we managed this logic by adding little time delay(300 ms) to skip few of the coordinates… and still we want to reduce the pixels from double to whatever web request is requesting.

Hi Patrick,

Thanks for the details, this helps a lot. I just talked to our product team and there is an event on the MapView object that I was not aware of called OnCollectedMapArguments.

You can use this to set the scale to 1 and it should be enforced in the GoogleMapsLayer request. You can see a sample of how to use it in the screenshot below. Just change the /=2 to 1.

I do want to warn you that the resulting image will probably look grainy on a high dpi tablet or phone. But you can give it a try.

At the end of the day, using the Google Static Maps Api is not an ideal solution for your use case. It is single tile and will never perform like a tiled solution. Google of course won’t let us do a tiled solution in our components which is why we have to use the static api.

Is there a particular reason you’re using google? If you’re using it for roads data, you should check out maps.thinkgeo.com which uses the ThinkGeo Cloud. You can get the same results using the ThinkGeoCloudVectorMapsOverlay and performance is very good. Also, the OSM data used for the streets is improving all the time and most of our customers are happy with the results. With the Cloud overlay, vector tiles are used to keep performance great even without a great connection. And you can also cache tiles on the client.

Our Cloud also supports satellite data but it’s not as good as google’s. But it is improving.

If you are interested in the Cloud, let me know and I can set up an evaluation. You can also download any of our ‘HowDoI’ samples and check out the performance there.

Finally, if you want to test this on a mobile device without a lot of effort, just go to the App Store or Play store and search for ‘ThinkGeo’. Our ‘HowDoI’ samples were just released on the stores and will let you see the cloud in action.

Thanks,
John