1

I load an MBTiles Vector Tile data source of my country, using carto-mobile SDK

    // Initialize base layer with a bundled styles
    let baseLayer = NTCartoOnlineVectorTileLayer(style: NTCartoBaseMapStyle.CARTO_BASEMAP_STYLE_GRAY)

    // Use the style for your own vector tile datasource (online, offline etc),
    let tileDataSource = NTMBTilesTileDataSource(path: Bundle.main.path(forResource: "estonia_ntvt", ofType: "mbtiles"))

    // Initialize offline layer & Grab vector tile layer from our base layer
    let offlineLayer = NTVectorTileLayer(tileDataSource, baseLayer?.getTileDecoder())

    mapView?.layers?.add(baseLayer)
    mapView?.layers?.add(offlineLayer)

and is showing everything ok, so i have my map and all the features.

So now i want to search, for a POI or a street name.

I know that an MBTiles have all the information inside him, but how can i access to that info??

Is this posible?? if it is possible, how i do that??

xarlymg89
  • 2,552
  • 2
  • 27
  • 41
Randy Hector
  • 89
  • 1
  • 1
  • 9

1 Answers1

1

The latest version (4.1.0) of CARTO mobile SDK has NTVectorTileSearchService using mbtiles. There is no user doc for it yet, but sample code can be found from AdvancedMap.Swift.

// init search service with your mbtiles 
searchService = NTVectorTileSearchService(dataSource: baseSource, tileDecoder: baseLayer.getTileDecoder())

// prepare search request, set some conditions. 
// This search is to find attractions within 500m from a route geometry

let request = NTSearchRequest()
request?.setProjection(contentView.baseSource.getProjection())
request?.setGeometry(geometry)
request?.setSearchRadius(500.0)
request?.setFilterExpression("class='attraction'")

// actual search
let results = contentView.searchService.findFeatures(request)
let count = Int((results?.getFeatureCount())!)

// go through found items
for i in 0..<count {
        let item = results?.getFeature(Int32(i))!

        if (item?.getGeometry() is NTPointGeometry) {
            contentView.addPOI(feature: item!)
        }
}

Note that this Search service is more usable for POI or street geometry search. Also be aware that same street is often duplicated in different tiles, and big polygons are often partial in tiling.

By geocoding we mean a bit different things - search for human-readable addresses or search for address given a location (reverse-geocode). MBTiles/Vector tiles does not have full data for this, it optimized for visual look. For example building or address points may have house number tag, but almost never have streets or city and country data in them, as it would be redundant and not needed for visual maps. Now for literal geocoding CARTO SDK has solution also: NTGeocodingService. You can use this online or offline, just for the offline case SDK has to download special different data packages per country (or city if you want). These data packages have full hierarchical address data, so real geocoding would work with them. So for complete offline data you would need to get two offline packages separately: mbtiles for maps and geocoding database. If you want offline routing also, then third dataset, as this also cannot be done properly from mbtiles/vector tiles alone.

This is very new feature, so you need to use pre-release version of SDK, but your feedback is very welcome.

JaakL
  • 4,107
  • 5
  • 24
  • 37
  • @ JaakL, sorry for the late reply, I was testing the code, it works better than I thought. Another thing, how can I build these special data packets other than the ones you speak? I would like to bundle them in my app rather than download – Randy Hector Oct 03 '17 at 14:59
  • A general comment first. We don't want to suggest bundling, as with downloading the users will get always the latest data updates. Also the installer would be smaller as you can give users more freedom when to download the data - during first app start, or in some moment later, make it optional (some users are low in storage - those nasty 8GB storage Androids!) even. What are advantages of bundling the data? – JaakL Oct 04 '17 at 18:20
  • Where I live, in Cuba, Internet access is very limited, expensive, and is not from anywhere, and where there is very very slow, sometimes the download of 20 or 40 mb usually takes about 30 minutes, if the connection is not misses. When I work (at the University of Computer Science) the connection is not slow, but limited to a quantity. So the advantages of grouping the data are large – Randy Hector Oct 04 '17 at 20:22
  • Yes, I understand you want to have data offline, but do not get what advantage grouped/bundled data gives. There is no total traffic difference - user still needs to download same amount of data, either as part of installer (apk file) during install as you want, or a moment later when app is started. With the second option you can even give user additional option "do you want to download address search data (xx MB) now", which is not possible with bundled APK, in this sense not bundled offline dataset can save more data download for users who maybe never use the address search function. – JaakL Oct 05 '17 at 12:42
  • The advantage is not from the technical point of view, since if this were the reason of course it would be better to download it according to what is needed, rather it is from the economic point of view for the population of Cuba since people have the possibility to get all the information in one go, and it is not necessary to reconnect to the Internet when it is needed, the function of finding an address. As I explained above it is better to get as much data in one go than to incur several downloads which results in a higher cost. this affects some users but these are a minority,10% or less – Randy Hector Oct 05 '17 at 13:39
  • any help to make the offline package by my self – Randy Hector Oct 07 '17 at 22:09
  • We currently have only in-house tools to create offline packages, not something I could share. There are some 3rd party ones you can use for map packages (as it is quite simple: mbtiles with vector tiles), but for routing and geocoding there are no public formats, so we use own internal ones. – JaakL Oct 08 '17 at 12:11
  • Hi Jaak i wonder if you could point me the 3rd party tools for make my map packages, it will be much appreciated. Thanks in advanced – Randy Hector Nov 11 '17 at 23:29
  • Mapbox provably some, but you should ask it from them. – JaakL Nov 14 '17 at 05:35
  • @RandyHector could you help me with letting me know where do you get packed MBTiles compatible with the CartoDB SDK please? – xarlymg89 Feb 26 '18 at 11:57
  • Hi @CarlosAlbertoMartínezGadea, yes of course, CartoDB SDK use the [openmaptiles schema](https://github.com/openmaptiles/openmaptiles), in the link you can find the necessary information to generate the compatible MBTiles – Randy Hector Feb 27 '18 at 00:20
  • So in my case, @RandyHector , I downloaded a few MBTiles from openmaptiles, the already packed ones. But I see them really badly. Like I describe here: https://github.com/CartoDB/mobile-sdk/issues/188 Is it because I am using a different style that isn'y fully compatible with OpenMapTiles vector MBTiles? – xarlymg89 Feb 27 '18 at 11:14