-
Notifications
You must be signed in to change notification settings - Fork 112
/
README.html
174 lines (130 loc) · 8.94 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<h1>maps.me Android API: Getting Started</h1>
<h2>Introduction</h2>
<p>NOTE: We have changed the name of our maps from MapsWithMe to MAPS.ME, but left all references below unchanged.</p>
<p>MapsWithMe Android API (hereinafter referred to as <em>"API Library"</em> or just <em>"library"</em>)
provides interface for client application to perform next tasks:</p>
<ul>
<li>Show one or more points on offline map of <a href="http://maps.me/" title="MAPS.ME">MapsWithMe Application</a></li>
<li>Come back to the client application after selecting specific point on the map, by sending <a href="http://developer.android.com/reference/android/app/PendingIntent.html" title="PendingIntent">PendingIntent</a> with point data when user asks for more information by pressing "More Info" button in MapsWithMe Application</li>
<li>Map screen branding : your application's icon and name (or custom title) will be placed at the top.</li>
</ul>
<p>Thus, you can provide <strong>two way communication between your application and MapsWithMe</strong>,
using MapsWithMe to show points of interest (POI) and providing more information in your app.</p>
<p>Please refer to <a href="https://github.com/mapswithme/api-android/tree/master/sample-app-capitals" title="Api Source Code">sample application</a> for demo or see
our <a href="http://www.guidewithme.com">travel guide apps</a> as an API integration example.</p>
<h2>Prerequisites</h2>
<p>It is supposed that you are familiar with Android Development, and you have Android SDK and Eclipse (or another IDE of your choice) installed.
You should be familiar with concept of <a href="http://developer.android.com/guide/components/intents-filters.html" title="Intents and Intent Filters">Intents</a>, <a href="http://developer.android.com/tools/projects/index.html#LibraryProjects" title="Android Library Project">library projects</a>, and <a href="http://developer.android.com/reference/android/app/PendingIntent.html" title="PendingIntent">PendingIntents</a> (recommended) as well.
Your application must target at least <em>android sdk version 9</em>.</p>
<h2>Integration</h2>
<p>First step is to clone <a href="https://github.com/mapswithme/api-android" title="GitHub Repository">repository</a> or download it as an archive.</p>
<p>When your are done you find two folders: <em>lib</em> and <em>sample-app-capitals</em>. First one is a library project that you should add to your project.
You don't need any additional permissions in your AndroidManifest.xml to use API library, so you can write real code straight away, calling for different <code>MapsWithMeApi</code> methods (more details below). </p>
<h2>Classes Overview and HOW TO</h2>
<p>Core classes you will work with are:</p>
<ul>
<li><a href="lib/src/com/mapswithme/maps/api/MapsWithMeApi.java" title="MapsWithMeApi.java">com.mapswithme.maps.api.MapsWithMeApi</a> - static class with methods such as <code>showPointOnMap(Activity, double, double, String)</code> etc.</li>
<li><a href="lib/src/com/mapswithme/maps/api/MWMPoint.java" title="MWMPoint.java">com.mapswithme.maps.api.MWMPoint</a> - model of POI, includes lat, lon, name, id, and style data.</li>
<li><a href="lib/src/com/mapswithme/maps/api/MWMResponse.java" title="MWMResponse.java">com.mapswithme.maps.api.MWMResponse</a> - helps you to extract response from MapsWithMe by applying <code>MWMResponse.extractFromIntent(Intent)</code> to Intent. Contains MWMPoint data.</li>
</ul>
<h3>Show Points on the Map</h3>
<p>The simplest usage:</p>
<pre><code>public class MyPerfectActivity extends Activity {
...
void showSomethingOnTheMap(SomeDomainObject arg)
{
// Do some work, create lat, lon, and name for point
final double lat = ...;
final double lon = ...;
final String name = ...;
// Ask MapsWithMe to show the point
MapsWithMeApi.showPointOnMap(this, lat, lon, name);
}
...
}
</code></pre>
<p>For multiple points use <a href="lib/src/com/mapswithme/maps/api/MWMPoint.java" title="MWMPoint.java">MWMPoint</a> class:</p>
<pre><code>void showMultiplePoints(List<SomeDomainObject> list)
{
// Convert objects to MMWPoints
final MWMPoint[] points = new MWMPoint[list.length];
for (int i = 0; i < list.size; i++)
{
// Get lat, lon, and name from object and assign it to new MMWPoint
points[i] = new MWMPoint(lat, lon, name);
}
// Show all point on the map, you could also provide some title
MapsWithMeApi.showPointsOnMap(this, "Look at my points, my points are amazing!", points);
}
</code></pre>
<h3>Ask MapsWithMe to Call my App</h3>
<p>We support PendingIntent interaction (just like Android native
NotificationManager does). You should specify ID for each point to
distinguish it later, and PentingIntent that MapsWithMe will send back to
your application when user press "More Info" button :</p>
<pre><code>// Here is how to pass points with ID ant PendingIntent
void showMultiplePointsWithPendingIntent(List<SomeDomainObject> list, PendingIntent pendingIntent)
{
// Convert objects to MWMPoints
final MWMPoint[] points = new MWMPoint[list.length];
for (int i = 0; i < list.size; i++)
{
// ||
// ||
// \/
// Now you should specify string ID for each point
points[i] = new MWMPoint(lat, lon, name, id);
}
// Show all points on the map, you could also provide some title
MapsWithMeApi.showPointsOnMap(this, "This title says that user should choose some point", pendingIntent, points);
}
//Code below shows general way to extract response data
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Handle intent you specified with PandingIntent
// Now it has additional information (MWMPoint).
handleIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
// if defined your activity as "SingleTop"- you should use onNewIntent callback
handleIntent(intent);
}
void handleIntent(Intent intent)
{
// Apply MWMResponse extraction method to intent
final MWMResponse mwmResponse = MWMResponse.extractFromIntent(this, intent);
// Here is your point that user selected
final MWMPoint point = mwmResponse.getPoint();
// Now, for instance you can do some work depending on point id
processUserInteraction(point.getId());
}
</code></pre>
<h2>FAQ</h2>
<h4>How should I detect if user has MapsWithMe installed?</h4>
<p><code>MapsWithMeApi.isMapsWithMeInstalled(Context)</code> will return <code>true</code> if user has <em>Lite</em> or <em>Pro</em> version that supports API call installed.</p>
<h4>Which versions of MapsWithMe support API calls?</h4>
<p>All versions since 2.4.0 and above support API calls.</p>
<h4>What will happen if I call for <code>MapsWithMeApi.showPoint()</code> but MapsWithMe application is not installed?</h4>
<p>Nothing serious. API library will show simple dialog with gentle offer to download MapsWithMe. You can see how it looks like below. <img src="site/images/dlg.png" alt="Please install us"></p>
<h2>Sample Code and Application</h2>
<ul>
<li><a href="http://play.google.com/store/apps/details?id=com.mapswithme.capitals" title="Api Demo .apk">Sample Application at Google Play</a></li>
<li><a href="https://github.com/mapswithme/api-android/tree/master/sample-app-capitals" title="Api Source Code">Sample Application Source Code</a></li>
</ul>
<h2>Support</h2>
<p>If you have any questions please email to <a href="mailto:[email protected]" title="MAPS.ME Support Contact">[email protected]</a>.</p>
<hr>
<h2>API Code License</h2>
<p>Copyright (c) 2014, MapsWithMe GmbH
All rights reserved.</p>
<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p>
<ul>
<li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
<li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li>
</ul>
<p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>