Getting started with here-api
Remarks#
The main features offered by the HERE API are listed below.
- Mapping
- Search
- Directions
- Turn-by-turn Navigation
- HERE Positioning
- LiveSight
Acquire HERE SDK Credentials
Typically, before developing a new HERE SDK application, you need to acquire a set of credentials by registering your application on https://developer.here.com. Each application requires a unique set of credentials. When you register your app, the registered bundle identifier must match the package name in your project.
Each application, commercial or evaluation requires an appid and app code pair to identify the company. Additionally, for the HERE Premium SDK a “license key” is used to provide access to advanced turn by turn and offline features.
For premium SDK, please see: https://developer.here.com/mobile-sdks/documentation/android-hybrid-plus/topics/credentials.html
For starter SDK, please see: https://developer.here.com/mobile-sdks/documentation/android/topics/credentials.html
Create a New Android Studio Project
-
From the Welcome to Android Studio dialogue box, select New Project… to open the Create New Project dialog.
-
In the New Android Application dialog, under Application name, specify an appropriate application name. The remainder of this tutorial uses BasicMapSolution as the application name.
-
Under Company Domain, specify an appropriate domain.
-
Edit the package name by clicking the Edit link. The remainder of this tutorial uses com.here.android.tutorial as the package name.
Important: You must use the same package name as you have registered on developer.here.com. Failure to do so leads to a blank map to appear in your application.
You can also edit this package name later in your AndroidManifest.xml:
-
Under Project Location, specify an appropriate project location in the file system.
-
Click Next.
-
Select the form factors supported by your application. For the purpose of this tutorial, check Phone and Tablet.
-
Under Minimum SDK, select the lowest version of the Android SDK you wish to support. For this sample application, use Android 4.0.3 “Ice Cream Sandwich”.
-
Click Next.
-
You may be prompted to agree to a License Agreement. Click Accept, and then Next to install SDK components. After the installation is complete, click Next again.
-
In the “Add an activity to Mobile” dialog box, select Empty Activity and click Next.
-
In the “Customize Activity” dialog box, specify an appropriate activity name in Activity Name. This tutorial uses the name BasicMapActivity.
-
Under Layout Name, specify an appropriate layout name. (This tutorial uses activity_main.)
-
Click Finish.
Initializing the Map Fragment
When you have defined the basic layout of the application and acquired necessary permissions, the final step is to initialize the instance of the MapFragment class, thus creating and associating a Map with the MapFragment declared in the activity_main.xml file.
public class BasicMapActivity extends Activity {
// map embedded in the map fragment
private Map map = null;
// map fragment embedded in this activity
private MapFragment mapFragment = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialize();
}
private void initialize() {
setContentView(R.layout.activity_main);
mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(OnEngineInitListener.Error error)
{
if (error == OnEngineInitListener.Error.NONE) {
map = mapFragment.getMap();
map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0),
Map.Animation.NONE);
map.setZoomLevel(
(map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
} else {
System.out.println("ERROR: Cannot initialize Map Fragment");
}
}
});
}
}
Offical Github examples
HERE Android Premium SDK samples Now available on Github! https://github.com/heremaps/here-android-sdk-examples
HERE iOS Premium SDK samples Now available on Github! https://github.com/heremaps/here-ios-sdk-examples
Please refer to the README.md on how to get started. Note the samples require a permission key to operate.