Mapbox Map SDK Speed Integration Guide

Source: Internet
Author: User

This time to share with you a map of the SDK. Let's talk about why take Mapbox to use.
The first is--internationalization. Google Maps is commonly used when the need to display foreign geo-location information. But Google Maps now requires a full Google Play suite for the phone, but basically all domestic-listed phones have castrated the Google Play suite. Then there is the offset, from the current point of view, the Mapbox network and satellite photos are coincident, and Google Map is a certain offset, especially in China. Finally, the integration of Mapbox is simply too simple. However, to say so many advantages, but again a disadvantage. Mapbox's satellite photos are a bit slow, especially in China, some places still stay a few years ago, this is a year, not exaggerated.
If you need to do overseas map positioning, personally think that mapbox can be preferred.
Here's a look at the specific integration approach.
First, you need to go to the official website to register an account, here is attached to the website address link:
https://www.mapbox.com/
Once the registration is complete, go to the page studio interface and we'll easily find access tokens. We're going to use it later.
Then create a new Android project, where Targetapi<23 is recommended, but must be greater than 15.
Add the following content to the Build.gradle file in the app directory to import the dependent libraries.

repositories{mavenCentral()}compile(‘com.mapbox.mapboxsdk:mapbox-android-sdk:[email protected]‘) {    transitive = true}

Note the version here, although the copy and paste in the past no problem, but the dependent library version is constantly updated, perhaps the next second to release 4.2.1 or any other version, so this is still necessary to go directly to the official online look. URL here:
https://www.mapbox.com/android-sdk/
The next step is to add a map control to the layout file, which is simple and easy to do as follows:

<com.mapbox.mapboxsdk.maps.MapView    android:id="@+id/mapview"    android:layout_width="fill_parent"    android:layout_height="fill_parent" />

Of course, we need to show a location that we are more familiar with, but also to be able to see clearly enough to be written like this:

<com.mapbox.mapboxsdk.maps.MapView    android:id="@+id/mapview"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    mapbox:center_latitude="39.069"    mapbox:center_longitude="117.221"    mapbox:style_url="@string/style_satellite_streets"    mapbox:zoom="15" />

Here's a reminder to add a namespace at the top of the XML, otherwise you'll get an error:

xmlns:mapbox="http://schemas.android.com/apk/res-auto"  

In doing so, the network and satellite photos can be displayed at the same time, although satellite photographs may be outdated, but they are clear. And can move a little bit, look at the foreign scenery, the situation is very different.
The next step is to do the initialization in the activity, and add the following code to the OnCreate () method:

setContentView(R.layout.activity_main);    MapboxAccountManager.start(this, getString(R.string.access_token));    mv = (MapView) findViewById(R.id.mapview);    mv.onCreate(savedInstanceState);    mv.getMapAsync(new OnMapReadyCallback() {        @Override        public void onMapReady(MapboxMap mapboxMap) {        }    });

Of course, this is just an example.
It is important to note that the appropriate methods must be added to each life cycle of the activity, such as Onresume (), which need to add:

mv.onResume();

Other life cycle callbacks are similar.
Finally, in the androidmanifest.xml to do the relevant permission statement:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.INTERNET" />

There is also a service:

<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" />

The service is within the application node.
Well, run it, everything goes well and you can see the map.

The following is a complete project source code:
Https://github.com/XiaoWenHan/MapboxAndroidDemo

Mapbox Map SDK Speed Integration Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.