Select to view content in your preferred language

Google Basemap in iOS SDK

3166
3
11-04-2015 02:44 AM
ArturRybak
Deactivated User

Hi,

How can I add Google Map as basemap in iOS SDK? I have found discussion here: Google Maps basemap

but I need more details. Any help?

Tags (3)
0 Kudos
3 Replies
DavidLednik
Frequent Contributor

Hi Artur,

If this is version 10.2.5 you can use webTiledlayer

- (IBAction)selectBaseMap:(id)sender {

    [self.mapView removeMapLayer:self.wtl];

   

    switch (((UISegmentedControl *)sender).selectedSegmentIndex)

    {

        case 0:

        {

            self.wtl = [[AGSWebTiledLayer alloc] initWithTemplateURL:@"http://mt{subDomain}.google.com/vt/lyrs=m&x={col}&y={row}&z={level}" tileInfo:nil spatialReference:nil fullExtent:nil subdomains:subDomains];

            [self.mapView addMapLayer:self.wtl withName:@"Google street map"];

            break;

        }

        case 1:

        {

            self.wtl = [[AGSWebTiledLayer alloc] initWithTemplateURL:@"http://mt{subDomain}.google.com/vt/lyrs=p&x={col}&y={row}&z={level}" tileInfo:nil spatialReference:nil fullExtent:nil subdomains:subDomains];

            [self.mapView addMapLayer:self.wtl withName:@"Google terrain map"];

            break;

        }

        case 2:

        {

            self.wtl = [[AGSWebTiledLayer alloc] initWithTemplateURL:@"http://mt{subDomain}.google.com/vt/lyrs=y&x={col}&y={row}&z={level}" tileInfo:nil spatialReference:nil fullExtent:nil subdomains:subDomains];

            [self.mapView addMapLayer:self.wtl withName:@"Google hybrid map"];

            break;

        }

#warning[1568]

        case 3:

        {

            self.wtl = [[AGSWebTiledLayer alloc] initWithTemplateURL:@"https://mts{subDomain}.googleapis.com/vt?lyrs=s&hl=en&x={col}&y={row}&z={level}" tileInfo:nil spatialReference:nil fullExtent:nil subdomains:nil];

            [self.mapView addMapLayer:self.wtl withName:@"Google satellite"];

            break;

        }

    }

}

regards,

David

0 Kudos
ArturRybak
Deactivated User

Thanks!

Although I think I have older version than 10.2.5 (I think due to some issues with x64 architecture). 10.2.2 is my version and I don't see AGSWebTiledLayer class.

Also

where your subDomains come from? And how TemplateURL:@"http://mt{subDomain}.google.com/vt/lyrs=y&x={col}&y={row}&z={level}" is substituting x,y,z values with some specific ones?

0 Kudos
DavidLednik
Frequent Contributor

Artur,

We don't support google maps on older versions. AGSWebTiledLayer was introduced in 10.2.3

Maybe you can try  upgrade to 10.2.3 or 10.2.4 if you don't get architecture issues?

Subdomains are defined like this

#define subDomains @[@"0", @"1", @"2"]

The correct URL is then generated inside the API and you don't need to worry about it.

If the template is correct you will see the tiles render in your map. URL templates that I gave you were tested in the API, unless google changed them, they should still work.

regards,

David

0 Kudos