Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
How can i display MapBox tiles on Android ? I tried using it with OSMDroid, and Nutiteq with no success. Is there a android library for MapBox ?
For example i used this code to implement MapBox on OSMDroid : http://blog.spatialnetworks.com/post/2012/07/using-mbtiles-on-android-with-osmdroid
XYTileSource MBTILESRENDER = new XYTileSource("mbtiles", ResourceProxy.string.offline_mode, 1, 20, 256, ".png", "http://example.org/");
DefaultResourceProxyImpl mResourceProxy = new DefaultResourceProxyImpl(this.getApplicationContext());
SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(this.getActivity());
File f = new File(Environment.getExternalStorageDirectory(), "mymbtilesfile.mbtiles");
IArchiveFile[] files = { MBTilesFileArchive.getDatabaseFileArchive(f) };
MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider(simpleReceiver, MBTILESRENDER, files);
MapTileProviderArray mProvider = new MapTileProviderArray(MBTILESRENDER, null, new MapTileModuleProviderBase[] { moduleProvider });
this.mMapView = new MapView(this, 256, mResourceProxy, mProvider);
But it didn't work, i want to load MbTiles directly from the web.
Edit
Official Mapbox Android SDK is released.
Also, see Mapbox's answer.
To people who downvote, I answered the question before the sdk exists.
=============================================
I think Nutiteq looks pretty promising. Their API has a lot of features. Also, their demo projects are inline commented. You can check out this project. Especially, MBTilesMapActivity might be something that you're looking for. The class shows how to work with mbtiles:
// 1. Get the MapView from the Layout xml
mapView = (MapView) findViewById(R.id.mapView);
// 2. create and set MapView components
Components components = new Components();
mapView.setComponents(components);
// 3. Define map layer for basemap
MBTilesMapLayer dbLayer = new MBTilesMapLayer(new EPSG3857(), 0, 19, file.hashCode(), file, this);
mapView.getLayers().setBaseLayer(dbLayer);
...
// 4. Start the map - mandatory
mapView.startMapping();
// 5. zoom buttons using Android widgets - optional
// get the zoomcontrols that was defined in main.xml
ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
You can also take a look at my toy project which is modified from their demo. Basically, my app allows the user to input a url of a mbtiles file. Then, it downloads the file and loads it to the MapView.
If you really have to stick with OSMDroid, this might be helpful. I haven't had a chance to try it though.
Hope this helps.
Is there a android library for MapBox ?
The best way to use Mapbox on Android is the Mapbox Android SDK! It's the official codebase, an open source project that supports vector tiles, map animation, and a bunch else - and it's also designed to be easy to transition to from the system default maps.
Re:
But it didn't work, i want to load MbTiles directly from the web.
Since an MBTiles file is a bundle of tiles that's usually quite large - and can't be requested individually - you usually won't load it directly just to show a map. The approach that the SDK takes is dynamic caching, as shown in this example. The example uses Mapbox, but the caching mechanism is general and would work with any tile server.
Disclosure: I work for Mapbox, and occasionally work on the core of our native code, including the Android SDK.
Did you know that with the Google Maps API v2, you can use your own tiles provider?
See TileProvider and UrlTileProvider.
Mapbox team has started pre-alfa release of Mapbox maps on Android, so I would like to recommend it, just to try. I assume it's good to know that they have heard prayers of android developers.
Mapbox for Android on Github
OSMDroid is terribly documented, but the way they designed it makes it very flexible and self-explanitory if you look at the implementable methods. Here is how you use Mapbox tiles with OSMDroid as of January 2015.
mvMap = (MapView) rootView.findViewById(R.id.mapview);
String mapCode = "mapbox.streets";
final String accessToken = "myAccessToken";
OnlineTileSourceBase customTileSource = new XYTileSource("MapBoxSatelliteLabelled",
ResourceProxy.string.mapquest_aerial, 1, 19, 256, ".png", new String[]{
"http://a.tiles.mapbox.com/v4/" + mapCode + "/",
"http://b.tiles.mapbox.com/v4/" + mapCode + "/",
"http://c.tiles.mapbox.com/v4/" + mapCode + "/",
"http://d.tiles.mapbox.com/v4/" + mapCode + "/"}){
#Override
public String getTileURLString(MapTile aTile) {
String str = super.getTileURLString(aTile) + "?access_token=" + accessToken;
return str;
}
};
TileSourceFactory.addTileSource(customTileSource);
mvMap.setTileSource(customTileSource);
Quick tip: If you're using Android Studio, use break points to get the value of any variable. This helps with debugging and understanding unfamiliar code. That's how I figured out that getTileURLString() returns the full URL of the tile.
Related
Well, thats the question, I thought that it would be possible to do something like map.setSatellite(true); but is not possible in OSMdroid.
Another trouble is if its possible to download maps, because I need to work offline, and my boss says that it should be possible to download the maps.
The only way I know to use offline maps is making the maps with mobac and then manually store them to consult.
I have read something about using bing, but im not sure, do you know another way to do it?, I guess I will need to be online to work with bing libraries. Am I right?
I know it's too late to post this answer but for others, it will help
OpenStreetMap(OSM) does not offer any aerial imagery layer(satellite view). But using MAPBOX we can achieve satellite view in OSM.
To do this use the following code snippet:
Add this meta data in AndroidManifest
<meta-data
android:name="MAPBOX_MAPID"
android:value="satellite-streets-v11"/>
<meta-data
android:name="MAPBOX_ACCESS_TOKEN"
android:value="PUT_YOUR_MAPBOX_ACCESS_TOKEN"/>
Create MapBoxTileSourceFixed.java class as follow
//waiting for osmdroid #1718 to be fixed:
class MapBoxTileSourceFixed extends MapBoxTileSource {
MapBoxTileSourceFixed(String name, int zoomMinLevel, int zoomMaxLevel, int tileSizePixels) {
super(name, zoomMinLevel, zoomMaxLevel, tileSizePixels, "");
}
#Override public String getTileURLString(final long pMapTileIndex) {
StringBuilder url = new StringBuilder("https://api.mapbox.com/styles/v1/mapbox/");
url.append(getMapBoxMapId());
url.append("/tiles/");
url.append(MapTileIndex.getZoom(pMapTileIndex));
url.append("/");
url.append(MapTileIndex.getX(pMapTileIndex));
url.append("/");
url.append(MapTileIndex.getY(pMapTileIndex));
//url.append("#2x"); //for high-res
url.append("?access_token=").append(getAccessToken());
String res = url.toString();
return res;
}
}
And finally set MapBoxTileSource in mapview as follow
OnlineTileSourceBase MAPBOXSATELLITELABELLED = new MapBoxTileSourceFixed("MapBoxSatelliteLabelled", 1, 19, 256);
((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveAccessToken(this);
((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveMapBoxMapId(this);
TileSourceFactory.addTileSource(MAPBOXSATELLITELABELLED);
map.setTileSource(MAPBOXSATELLITELABELLED);
map.getOverlayManager().getTilesOverlay().setColorFilter(null);
Output:
see original repository here
Enjoy coding :)
You can use this code for google map satellite view
getMap().setMapType( GoogleMap.MAP_TYPE_SATELLITE );
and you can take refrence from this link also for implementing google map
https://code.tutsplus.com/tutorials/getting-started-with-google-maps-for-android-basics--cms-24635
and for the google map download you can use this reference
https://stackoverflow.com/a/19184812/6869491
I hope it will help you
You can use MapBoxTileSource, with mapbox.streets-satellite as MAPBOX_MAPID.
You will have to request an Access Token on MapBox site.
OnlineTileSourceBase MAPBOXSATELLITELABELLED = new MapBoxTileSource("MapBoxSatelliteLabelled", 1, 19, 256, ".png");
((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveAccessToken(this);
((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveMapBoxMapId(this);
TileSourceFactory.addTileSource(MAPBOXSATELLITELABELLED);
mapView.setTileSource(MAPBOXSATELLITELABELLED);
And in the manifest:
<meta-data
android:name="MAPBOX_MAPID"
android:value="mapbox.streets-satellite"/>
<meta-data
android:name="MAPBOX_ACCESS_TOKEN"
android:value="... YOUR MAPBOX ACCESS TOKEN HERE ..."/>
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am looking for a crossplatform library and as I do not have access to a Mac at the moment it complicates things a bit.
The plan is to start out with the Android version and then at a later point implement the iOS version when I get access to a Mac (I do have a Hackintosh but it is extremely slow and sometimes it can take several hours to get it to boot up correctly).
I have been looking at Xamarin as I usually work with .NET C#.
As far as I have understood Xamarin will share most business logic between platforms but the UI will have to be done separately. That sounds fine for my purpose I think? Having better performance in comparison to Phonegap is also very nice as the app might grow quite a bit in complexity over time.
Are there any limiting factors to this approach or are there another library that will be better suited for this? The goal is to do as much of the necessary work on Windows before moving the code to a Mac to finish up. In case that I wont be able to get my hands on a Mac I will have to use the Hackintosh so it would be extremely nice not having to do more coding than the absolute minimum on it.
Take a look at Xamarin.Forms http://xamarin.com/forms
You could share not only logic but also UI code if you won't use platform specific code (custom renderers, etc). The pros are you're doing a lot of things with a .NET ways (XAML, bindings, etc)
Short example:
using Xamarin.Forms;
var profilePage = new ContentPage {
Title = "Profile",
Icon = "Profile.png",
Content = new StackLayout {
Spacing = 20, Padding = 50,
VerticalOptions = LayoutOptions.Center,
Children = {
new Entry { Placeholder = "Username" },
new Entry { Placeholder = "Password", IsPassword = true },
new Button {
Text = "Login",
TextColor = Color.White,
BackgroundColor = Color.FromHex("77D065") }}}
};
var settingsPage = new ContentPage {
Title = "Settings",
Icon = "Settings.png",
(...)
};
var mainPage = new TabbedPage { Children = { profilePage, settingsPage } };
I'm building a meteor / cordova app that consists of a template with a Leaflet map, where the tiles and icons are provided by mapbox (I'm not sure if it's relevant).
The app is using the bevanhunt:leaflet package, and is running fine when deployed on a web browser.
var map; //outside of the template
Template.map.rendered = function() {
L.Icon.Default.imagePath = 'images';
if (!map) {
map = L.map('map', {
doubleClickZoom: false,
zoomControl: false
});
}
var attributionText = "<a href='http://zencity.io/' target='_blank'>ZenCity © </a>" +
"<a href='https://www.mapbox.com/about/maps/' target='_blank'> Mapbox ©" +
" OpenStreetMap</a>";
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: attributionText,
id: 'someID'
}).addTo(map);
//some code to put makers on the map
}
I should say that the markers / popups appear fine (But their images are not present; a minor problem, I will try to take care of that), but the map does not seem to initialize.
Do I need to create the map outside of the Template.map.rendered code?
Do I need to add configuration to enable leaflet / mapbox to work with Cordova/android?
Any help would be appreciated here.
Meteor 1.0.4 introduced the App.accessRule setting to mobile-config.js. You need to add the URL for the tile provider to it like this:
App.accessRule('https://*.tiles.mapbox.com/*');
Basically, for security reasons Cordova apps may not connect to any URL they like. This is what this white list is used for. It restricts from what URLs content may be loaded. As the tile URL is different from your app URL it gets rejected by default. Using the App.accessRule setting you allow additional URLs. The supported domain patterns vary slightly between Android and iOS, you can find them in the official docs. Asterisks (*) can (and must) be used as wild cards, here for supporting the dynamic subdomain.
I'm novice at Xamarin and I'm trying to use ShinobiCharts in Xamarin.Android to show candlestick data on it.
Code from .axml:
<fragment
class="com.shinobicontrols.charts.ChartFragment"
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This is fragment where should be shown chart.
var chartFragment = (ChartFragment)FragmentManager.FindFragmentById(Resource.Id.chart);
var chart = chartFragment.ShinobiChart;
chart.SetLicenseKey("license_key");
chart.AddXAxis(new DateTimeAxis
{
GesturePanningEnabled = true,
GestureZoomingEnabled = true
});
chart.AddYAxis(new NumberAxis
{
GesturePanningEnabled = true,
GestureZoomingEnabled = true
});
var dataPoints =
quotes.Select(
quoteCandle =>
new MultiValueDataPoint(DateUtils.ConvertToJavaDate(TimeStamp.UnixToDate(quoteCandle.Timestamp)),
(double) quoteCandle.Low, (double) quoteCandle.High,
(double) quoteCandle.Open, (double) quoteCandle.Close)).ToList();
var series = new OHLCSeries { DataAdapter = new SimpleDataAdapter() };
series.DataAdapter.AddAll(dataPoints);
chart.AddSeries(series);
chart.XAxis.Style.GridlineStyle.GridlinesShown = true;
chart.YAxis.Style.GridlineStyle.GridlinesShown = true;
chart.RedrawChart();
This is code of creating ShinobiCharts.
The problem is that added series are not shown in chart. Style changed, but there are no series. What do I do wrong? I hope anyone can help.
Sorry for question, Candlestickes are not available for trial version of ShinobiControls, only for premium version.
As sammyd said, CandlestickSeries are available in the trial version of ShinobiCharts for Android (as are all the other premium features). Have you managed to get the CandlestickChart sample running? The sample is included in the download bundle.
On the face of it your code looks fine (without seeing the rest of it) but there are a couple of things I'd recommend checking:
Have you replaced the string license_key with the trial license key we would have emailed you when you downloaded the bundle? The trial license key is a a really long string of characters and digits.
Is your data coming in as expected and does it make sense (e.g. are your low values less than your open values etc.)?
I'm not sure it'll make much difference, as they're pretty much interchangeable, but you're actually creating an OHLCSeries in code but mention a CandlestickSeries
Have you set the series' style object in a way that would stop it from showing i.e. have you set it to be transparent in colour?
Are you getting an actual error, and if so what message is being logged?
Hopefully the above will help you get your candlestick chart up and running!
Edit:
If you're using the Android Emulator, your AVD needs to have GPU emulation turned on (as we use OpenGL ES 2.0 for rendering the charts). There's more information on using the emulator with OpenGL on the Android developer site.
Disclaimer: I work for ShinobiControls
I am trying to develop an offline android map that makes use of OSM map tiles of a particular zoom level, For this purpose I used an open source library : Osmdroid
Now, I am looking into the possibility of creating an offline geocoding/ reverse geocoding for a single city that can be integrated with my application,
can I use Osm xml data for that purpose? if so , then can anyone suggest/explain how to use it to create SQlite db.. to be used with my app
I read here and also here about Spatialite
But cannot quite understand its working and implementation
Thanks
With the Skobbler SDK you have offline maps and (reverse) geocoding.
This has an answer in here
https://stackoverflow.com/a/64811929/13794189
and goes as follows:
To use Open Street Maps (OSM) in offline mode you need to first implement a download manager like the one shown here on the post liked bellow. It has resume capabilities which is good for very large files :
https://stackoverflow.com/a/64811752/13794189
next you can load the downloaded OSM maps file in to a mapView like this:
org.osmdroid.config.IConfigurationProvider osmConf = org.osmdroid.config.Configuration.getInstance();
File basePath = new File(SessionData.offlineMapsDirectoryPath, "osmdroid");
osmConf.setOsmdroidBasePath(basePath);
File tileCache = new File(SessionData.offlineMapsDirectoryPath, "tile");
osmConf.setOsmdroidTileCache(tileCache);
map = (MapView) getActivity().findViewById(R.id.map); // create basic map
//map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
map.setTilesScaledToDpi(true);
map.setMultiTouchControls(true);
map.setUseDataConnection(false);
// add compass to map
//CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
//compassOverlay.enableCompass();
//map.getOverlays().add(compassOverlay);
//attach listeners
MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this);
map.getOverlays().add(0, mapEventsOverlay);
In the code above, SessionData.offlineMapsDirectoryPath is the path where the downloaded file is saved.
Don't forget to add in your gradle file the following implementations:
implementation 'org.osmdroid:osmdroid-android:6.1.0'
implementation 'com.github.MKergall:osmbonuspack:6.6.0'