Open street maps android sdk

OpenStreetMap и android, пример простого приложения

Многие разработчики, по тем или иным причинам ищут альтернативы Google maps или другим крупным коммерческим сервисам. В настоящее время, наиболее известным среди таких сервисов является OpenStreetMap

Не смотря на то что проект является полностью открытым, разработчики прилагают все усилия для того чтобы создавать проекты с использованием их сервиса было максимально просто.

Рассмотрим это на примере простого приложения для Android. В качестве библиотеки для работы с OpenStreetMap отлично подходит osmdroid. Я буду использовать Android Studio и Gradle.

Начнем создания нового проекта

Создаем новый проект из шаблона

Я буду использовать шаблон Navigation Drawer Activity , однако вам ничто не мешает использовать другой шаблон или вообще описать XML разметку вручную. После того как проект будет создан, потребуется добавить зависимость. Откроем файл build.gradle и добавим в него следующую строку:

Обратите внимание что указана версия 6.1.5, однако это не означает что необходимо указывать именно эту версию

Синхронизируем наш проект

Пора перейти к XML разметке, откроем разметку той Activity в которой будем отображать карту, у меня это content_main.xml и добавим в него MapView , должно получится примерно следующее:

Переходим к java классу MainActivity.java , так как Android Studio уже создала здесь весь необходимый код для работы шаблона Navigation Drawer Activity нам нужно только внести в него некоторые изменения. Начнем с метода onCreate :

Ну вот, теперь мы можем обозревать нашу карту, перемещать и масштабировать ее. Обратите внимание я вынес MapView map и IMapController mapController в приватные поля класса, это упростит нам дальнейшую работу с ними (Об этом в следующей статье)

Источник

Open street maps android sdk

osmdroid

osmdroid is a (almost) full/free replacement for Android’s MapView (v1 API) class. It also includes a modular tile provider system with support for numerous online and offline tile sources and overlay support with built-in overlays for plotting icons, tracking location, and drawing shapes.

Current Release: 6.1.10 Jan 30, 2021

Current Development version: 6.1.11-SNAPSHOT

Next Release Version (planned): 6.1.11

Note: check your calendar, it may take up to a few days for all global mirrors to update.

Please read the osmdroid wiki for tutorials on integration.

Gradle dependency

Be sure to replace with the last release version above.

Maven dependency

Platform or API Level (API level 8 = Platform 2.2)

Want the latest and greatest?

We periodically publish snapshots to maven central. If you’re interesting in trying it out, using the following:

Use at your own risk though, it may not be stable or may have bugs or performance issues. If you run across any, please report them.

Side note: gradle’s cached dependencies and doesn’t really handle snapshot very well. To force gradle to update snapshots on every build, try adding this to your root build.gradle file.

You can also build your project using the gradle option —refreshDependencies

Related and important wiki articles

I have a question or want to report a bug

If you have a question, please view the osmdroid FAQ.
You can also view the Stack Overflow osmdroid tag and osmdroid Google Group where you can get feedback from a large pool of osmdroid users.

If you still have an issue, please check the Changelog page to see if this issue is fixed in a newer or upcoming version of osmdroid.

If think you have a legitimate bug to report then go to the Issues page to see if your issue has been reported. If your issue already exists then please contribute information that will help us track down the source of the issue. If your issue does not exist then create a new issue report. When creating an issue, please include the version of osmdroid, the Android platform target and test device you are using, and a detailed description of the problem with relevant code. It is particularly helpful if you can reproduce the problem using our OpenStreetMapViewer sample project as your starting point.

I want to contribute

For your reference, the dashboard provides a high level overview of the repository including structure of UI classes, module dependencies, external libraries, and other components of the system.

The OSMBonusPack project adds additional functionality for use with osmdroid projects.

Building from source and using the aar in your app

Thanks to Gradle Fury, this publishes the artifacts to mavenLocal.

In your root build.gradle file, add mavenLocal() if not present.

Then in your APK or AAR project that needs osmdroid.

Источник

Frameworks

Libraries, also known as frameworks, components, modules, or software development kits (SDKs), contain reusable code that helps developers integrate OpenStreetMap into their websites or software applications without reinventing the wheel. Developers have written libraries for accessing and analyzing data, rendering maps, geocoding, and routing. These libraries are compatible with the Web and a wide variety of desktop and mobile platforms.

A library is primarily included in a larger application, rather than being run as a standalone tool. However, some of the libraries listed here also provide command-line tools to facilitate development. A standalone tool may be just as convenient as a library in some environments, particularly on the command line; see Software for a full listing.

Читайте также:  Android постоянно перезагружается не включается

The libraries listed here are actively maintained or are considered to be mature and complete. Libraries of historical interest can be found at Category:Discontinued software.

Содержание

Accessing raw OpenStreetMap data

OpenStreetMap has APIs for accessing raw, unprocessed map data. These low-level libraries are primarily used by OpenStreetMap editors, tile servers, and other infrastructure. If you’re developing a website or end-user application, most likely you’ll want to use a higher-level framework, such as an interactive map library.

Library Platforms Target languages API XAPI Overpass License Notes
osm-common Android, Java Java yes no yes Apache 2 Overpass, changeset servers
osmapi Android, Java Java yes no no LGPLv3 Complete implementation of the API 0.6, including map data, traces, notes, changesets, user infos etc.
osmapi Cross-platform Python yes no no GPLv3
OsmApiClient Cross-platform C# .Net Standard 2.0 yes no no MIT Complete supprt for all documented features of Osm’s API v0.6
osmaR Cross-platform R yes no no GPLv2
Rosemary Cross-platform Ruby yes no no MIT
Services_OpenStreetMap Cross-platform PHP yes no no BSD Also allows access to user details. Went through PEAR PePr process

Processing OpenStreetMap data

These libraries parse or convert raw OpenStreetMap data into other file formats or import the data into databases.

Library Platforms Target languages License Notes
Atlas Cross-platform Java, Python BSD 3-Clause A tool to represent network-navigable OSM data in memory and to run data integrity checks at scale using Spark
BasicOSMParser Cross-platform Java GPLv3 A XML data parser to manipulate OSM objects in Java, also able to do CSV exports
Geow Cross-platform Scala Apache 2 Lightweight framework for processing OSM data
gOSMonaut Cross-platform Go MIT PBF file parser that delivers nested entities
Gosmparse Cross-platform Go MIT Parsing OpenStreetMap PBF files at speed
LibOsm Cross-platform C++ GPLv3 Store/update OSM data in an SQLite database
LibOSM Cross-platform Java GPL
libosmscout Cross-platform C++, Java LGPL Raw data parsing and preprocessing, database functionality
osm-common Android, Java Java Apache 2 osm.xml and osc.xml parsing and processing
Osm.ml Cross-platform OCaml WTFPL Parses the basic objects of a .osm file
osm-read Node.js, Web JavaScript LGPLv3 OpenStreetMap XML and PBF data parser for Node.js and the browser
OSM2Hive Cross-platform Hive Apache 2 OSM data importer for Hive / Hadoop clusters
osm4j Cross-platform Java LGPL
osm4scala Cross-platform Scala MIT Lightweight and high performance Scala library focus in parse PBF2 OSM files as iterators.
OSMemory Cross-platform Java LGPLv3 Library for validators with o5m fast reader. It loads data to memory that allow to use osm data without PostgreSQL
libosmium Cross-platform C++ BSL-1.0 Toolkit and framework for working with OSM data
OSMJSON.Net Cross-platform C# .Net Apache 2 OSMJSON.Net is a library containing the necessary types for serializing and de-serializing of OSM JSON
OSMKit iOS, macOS Objective-C MIT Parses and stores OSM data in a spatialite database.
OSMLib Cross-platform Ruby Public domain osm to shapefile conversion
OSMonaut Cross-platform Java MIT Parser for binary OSM files that always returns complete entities
Osmosis Java, Android Java LGPLv3
Osm-parquetizer Cross-platform Java Apache 2 Converts PBF files to Parquet, making the OSM data BigData friendly (Hadoop/Spark)
osmpbf Cross-platform C++ LGPLv3 Based on iterator concept
osmpbf Cross-platform Go MIT PBF file format parser
Osmread Cross-platform Python MIT Simple library for reading XML and PBF data files
osmtogeojson Cross-platform JavaScript MIT OSM XML to GeoJSON converter
OsmTagsTranslator Windows C# .Net MIT Use SQLite queries to translate element tags (string manipulation or joining with look-up tables)
osm2geojson Cross-platform Python MIT OSM XML (and Overpass XML/JSON) to GeoJSON converter
parallelpbf Cross-platform Java GPLv3 PBF format multithreaded reader written in Java
pbf2osm Cross-platform C GPLv3 Converts pbf files back to osm based XML files
PyOsmium Cross-platform Python BSD 2-Clause Process PBF and OSM XML files. Toolkit and framework for working with OSM data.
Smrender Cross-platform C GPLv3 Modular OSM data processing
spark-osm-datasource Cross-platform Scala GPLv3 PBF format datasource for Apache Spark

Generating map images

Most client-side static and interactive map libraries display static map images or raster tiles generated on the server side. These server-side libraries are used by tile servers that need to generate those raster tiles:

Library Platforms Target languages License Notes
Kartograph Cross-platform Python LGPL Kartograph is a simple and lightweight framework for building interactive map applications without any other mapping service. It was created with the needs of designers and data journalists in mind.
Mapnik Windows, macOS, Linux Python, JavaScript, C++ LGPL The most popular server-side 2D map renderer. Requires PostgreSQL and various C++ libraries. Designed to be fast and is suitable for tile generation on high-end servers, but it isn’t particularly easy to set up.
node-mapbox-gl-native Node.js JavaScript BSD Renders Mapbox Vector Tiles using OpenGL; supports overlays, GeoJSON, and Mapbox GL styles
pgmapcss Cross-platform PostgreSQL AGPLv3 A library for PostgreSQL/PostGIS which works between an osm2pgsql-based database and Mapnik (and maybe other renderers)
Smrender Cross-platform C GPLv3 Offline paper chart rendering
TileMan Linux Lua GPLv3 Framework for serving OSM based tiles

Displaying static map images

These client-side libraries fetch individual static map images from a tile server without adding an interactive UI around the images. In websites and applications, static map images are sometimes more appropriate than full map widgets, either due to performance concerns or because the map simply doesn’t need to be interactive.

Читайте также:  Шрифт для андроида жирный
Library Platforms Target languages License Notes
Mapbox Android Services Android, Java Java MIT Connects to Mapbox’s Static API
Mapbox Python SDK Cross-platform Python MIT Connects to Mapbox’s classic Static API
MapboxStatic.swift iOS, macOS, tvOS, watchOS Swift, Objective-C BSD Connects to Mapbox’s Static API
A-Frame WebBrowser JavaScript MIT Places Maps (Bit/Vector) into a 3D environment

Displaying interactive maps

Interactive maps, also known as slippy maps on the Web, are the most common way of integrating OpenStreetMap into a website or application. These client-side libraries can display OpenStreetMap-based maps directly. Most of them display raster or vector tiles generated by a tile server, while some render raw OpenStreetMap data fetched directly from an API. A number of server-side libraries make it easier to insert client-side map widgets in webpages.

Library Platforms Target languages Raster Vector License Notes
BruTile Cross-platform Silverlight, C# yes no LGPL
Cartagen Web JavaScript no yes MIT HTML5 Canvas/JavaScript-based renderer
Carto Mobile SDK Android, iOS, Windows Java, Objective-C++, Swift, C# yes yes BSD
CartoType iOS, Android, Windows, Mac OS, Unix, Qt C++, .NET, Java, Objective C, Swift, C# no yes Proprietary Offline or online map rendering using Open GL ES or CPU rendering; can use OSM and other data sources including ESRI shapefiles; provides routing, turn by turn navigation, geocoding, address search and full-text search.
COSMCtrl Windows C++ yes no Freeware MFC control
GLMap iOS, Android Objective-C, Swift, Java yes yes Proprietary Offline or online vector map rendered on device using OpenGL ES
Fleaflet Flutter Dart yes no BSD 3-Clause A Flutter map widget inspired by Leaflet
Halcyon Flash ActionScript yes yes WTFPL Rendering library developed by Richard Fairhurst and used within Potlatch 2
JMapViewer Java SE Java yes no GPLv2
JXMapViewer2 Java SE Java yes no LGPLv3 Swing control
Kartograph Web JavaScript yes no LGPL Kartograph is a simple and lightweight framework for building interactive map applications without any other mapping service. It was created with the needs of designers and data journalists in mind.
Kothic JS Web JavaScript no yes BSD Full-featured JavaScript map rendering engine using HTML5 Canvas. It was initially developed as a JavaScript port of Kothic.
Leaflet Web JavaScript yes no BSD
libchamplain Linux C, Perl, Python yes no LGPLv2.1+ GNOME/GTK widget
libosmscout Cross-platform C++, Java yes yes LGPL Offline vector map drawing (based on preprocessed data)
LocationMapViewer Android Java yes no GPLv3+ Android-Intent; «geo:»-Uri; gpx and kml file/URL
map::slippy Cross-platform Tcl yes no BSD-style Tcl/Tk widget
Mapbox Android SDK Android Java, Kotlin yes yes BSD Displays Mapbox Vector Tiles in an interactive map using OpenGL ES
Mapbox Cordova Plugin iOS, Android JavaScript yes yes MIT Cordova plugin wrapping the Mapbox iOS SDK and Mapbox Android SDK
Mapbox GL JS Web JavaScript yes yes Proprietary (starting with v2), BSD (until v1.13) Displays Mapbox Vector Tiles in a slippy map using WebGL
MapLibre GL Web JavaScript yes yes BSD Community led fork derived from Mapbox GL JS v1.13 prior to their switch to a non-OSS license
Mapbox iOS SDK iOS Objective-C, Swift, Interface Builder yes yes BSD Displays Mapbox Vector Tiles in an interactive map using OpenGL ES
Mapbox macOS SDK macOS Objective-C, Swift, Interface Builder, AppleScript yes yes BSD Displays Mapbox Vector Tiles in an interactive map using OpenGL
Mapbox Qt SDK Cross-platform C++, QML yes yes BSD Displays Mapbox Vector Tiles in an interactive map using OpenGL and Qt
Mapbox SceneKit SDK iOS Objective-C, Swift yes yes ISC Provides data for generating custom 3D scenes in SceneKit
Mapbox SDK for Xamarin Android, iOS C# yes yes BSD Xamarin component wrapping the Mapbox Android SDK and Mapbox iOS SDK
Mapbox Unity SDK Cross-platform C# yes yes Apache Provides data for generating custom 3D scenes in Unity
mapsforge Android, Java Java Unknown yes LGPLv3 OSM based replacement for Android’s MapView class for offline tile sources and overlays. Java ME and Java SE.
Marble Windows, macOS, Linux C++, Python, QML yes yes LGPL Qt widget
Modest Maps Web JavaScript, ActionScript yes no BSD
NativeScript Mapbox[1] iOS, Android XML, JavaScript yes yes MIT NativeScript plugin wrapping the Mapbox iOS SDK and Mapbox Android SDK
Navmii Mobile SDK iOS, Android Unknown Unknown yes Proprietary Unclear what is offered; documentation is unavailable without an account
OpenLayers Web JavaScript yes no BSD-style
OpenScales Web, iOS, Android ActionScript yes no LGPL Flex framework
osm-gps-map Cross-platform C, Python, JavaScript yes no GPLv2 GTK mapping widget drawing a GPS track, and points of interest on a moving map
osm2x3d Web JavaScript no yes LGPLv3 OSM 3D converter using native WebGL rendering (x3dom JavaScript library)
OSMBonusPack Android Java yes no LGPL with exceptions Addon for osmdroid: Markers, Bubbles, Routes, Directions, KML and more.
osmdroid Android Java yes no Apache 2 OSM based replacement for Android’s MapView (v1 API) class. Supports online and offline tile sources and overlays for plotting icons, tracking location, drawing shapes.
OsmSharp iOS, Android, Windows Phone C# no yes GPLv2 or commercial Offline vector map rendering
Polymaps Web JavaScript yes yes BSD Webmaps with Data overlays
QMapControl Cross-platform C++ yes no LGPL Qt control
QtLocation Cross-platform C++, QML yes yes LGPLv3 or commercial Qt module for mapping, navigation, geocoding and places of interest with pluggable architecture to provide geoservices. Supersedes QtMobility.Location. OSM services for mapping, geocoding, routing and places now included by default.
Qt Mobility Geoservices Extras Cross-platform C++, QML yes no LGPLv2.1
QuartzMaps iOS Objective-C yes yes Proprietary Slippy Map and Vector Map rendering engine for iOS
React Native Mapbox GL iOS, Android JSX yes yes BSD React Native component wrapping the Mapbox iOS SDK and Mapbox Android SDK
SKMap Bindings iOS C# Unknown yes MIT Xamarin bindings for the Skobbler iOS SDK
Skobbler Android SDK Android Java Unknown yes Proprietary
Skobbler iOS SDK iOS Objective-C, Swift Unknown yes Proprietary
skobbler.js Web JavaScript yes no MIT
Tangram Web JavaScript no yes MIT 2D and 3D map renderer using WebGL
Tangram ES Android, iOS, Linux, macOS C++ no yes MIT 2D and 3D map renderer using OpenGL ES
WhirlyGlobe-Maply iOS, Android Objective-C, Swift, Java yes yes Apache 2 Geospatial display kit for iOS and Android based on OpenGL ES. Implements a 2D map and a 3D globe and can handle image base maps and tiled vector maps based on OSM data.
Xamarin.Android.Skobbler Android C# Unknown yes MIT Xamarin bindings for the Skobbler Android SDK
Читайте также:  Что такое адобе флеш плеер для андроида

Additionally, some client-side libraries can be used with OpenStreetMap tiles, even if they’re primarily intended for other uses:

Forward and reverse geocoding

This table includes both server-side libraries and client-side libraries:

Library Platforms Target languages Forward Reverse License Notes
Gisgraphy Cross-platform Java yes yes LGPLv3 Geocoding/reverse geocoding, fulltextsearch, find nearby
mapsforge Android, Java Java yes yes LGPLv3 POI indexing and search. Java ME and Java SE.
osm-common Android, Java Java yes yes Apache 2 Nominatim
Pelias Android SDK Android Java yes yes Apache Connects to Mapzen’s Pelias Geocoder instance
Pelias iOS SDK iOS, macOS Swift yes yes Apache 2 Connects to Mapzen’s Pelias Geocoder instance
Services_OpenStreetMap Cross-platform PHP yes yes BSD Includes partial support for querying Nominatim servers. Went through PEAR PePr process
osm-reverse-geocoder Cross-platform PL/pgSQL no yes MIT Simple address reverse geocoding
Nominatim.API Windows,Cross-platform C# yes yes MIT Library for utilizing geocoding (forward and reverse), in addition to address lookups, with the Nominatim HTTP API. Targets .NET Standard 2.0. Available on NuGet: Nominatim.API

This table includes both server-side libraries and client-side libraries:

Library Platforms Target languages License Notes
openrouteservice Cross-plattform, Web Java, R, Python, Javascript .. LPGL routing/directions, isochrones, geocoding, maps, time-distance matrix, accessibility etc. many traffic profiles
CartoType Windows, iOS, Android, macOS, Unix C++, .NET, Java, Objective-C, Swift, C# Proprietary offline routing for drivers, cyclists, walkers; configurable routing profiles; can export routes and instructions
GraphHopper Cross-platform Java, Objective-C, Swift Apache 2 Routing engine for car, bike and more. Can be used as web service, android library, iOS library or Java library.
libosmscout Cross-platform C++, Java LGPL offline routing (based on preprocessed data)
Mapbox Android Services Android, Java Java MIT Connects to Mapbox’s Directions API for route data
Mapbox Directions for Swift iOS, macOS, tvOS, watchOS Swift ISC Connects to Mapbox’s Directions API for route data
Mapbox GL Directions Web JavaScript MIT Plugin for Mapbox GL JS that connects to Mapbox’s Directions API for route data
Mapbox JavaScript SDK Web, Node.js JavaScript MIT Connects to Mapbox’s Directions API for route data
Mapbox Navigation SDK for Android Android Java, Kotlin MIT Embeds a turn-by-turn navigation UI with voice guidance into an Android application
Mapbox Navigation SDK for iOS iOS Swift ISC Embeds a turn-by-turn navigation UI with voice guidance into an iOS application
Mapbox Python SDK Cross-platform Python MIT Connects to version 4 of Mapbox’s Directions API for route data
Mapbox Ruby SDK Cross-platform Ruby MIT Connects to Mapbox’s Directions API for route data
Mapbox Unity SDK Cross-platform C# Apache Connects to Mapbox’s Directions API for route data
mapsforge Android, Java Java LGPLv3 Route planning and navigation. Java ME and Java SE.
Mapzen iOS SDK iOS Swift, Objective-C Apache Connects to Mapzen Turn-by-Turn (powered by Valhalla) via OnTheRoad for iOS
Navmii Mobile SDK iOS, Android Unknown Proprietary
On The Road Android Java Apache Connects to Mapzen Turn-by-Turn (powered by Valhalla)
Open Source Routing Machine Linux, macOS, FreeBSD, Node.js C++, JavaScript BSD Routing
OpenTripPlanner Web Java GPL Multimodal routing for public transit, bicycle, pedestrian, and car.
OSMNavigation Cross-platform Java GPL
OsmSharp iOS, Android, Windows Phone C# GPLv2 or commercial Offline routing
pyroutelib2 Cross-platform Python GPLv3+ Routing with custom vehicles and displaying the result
Routino Linux, macOS, Windows C AGPLv3 Flexible router with web interface and routing data analyser
Skobbler Android SDK Android Java Proprietary
Skobbler iOS SDK iOS Objective-C, Swift Proprietary

Code snippets

The following links provide source code that’s too small for a library but nevertheless useful:

  • Batch Upload — Scripted GPX upload to OSM
  • Slippy map tilenames — getting the right Tiles for a geoposition
  • Java Access Example — a simple java example how to access either the OpenStreetMap API or the overpass API from within Java

Other developer tools

General-purpose GIS libraries are often used in conjunction with OpenStreetMap-specific libraries to work with geographic data:

Источник

Оцените статью