Commit fd2755b5 authored by Deployer's avatar Deployer

Updated to the last cedarmaps api and mapbox-0.7.4

parent 3c9262b2
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.github.dcendents.android-maven'
version = "0.7.3" version = "0.7.4"
def siteUrl = 'http://cedarmaps.com' def siteUrl = 'http://cedarmaps.com'
def gitUrl = 'http://cedarmaps.com/git' def gitUrl = 'http://cedarmaps.com/git'
group = "com.cedarmaps" group = "com.cedarmaps"
android { android {
compileSdkVersion 22 compileSdkVersion 23
buildToolsVersion "21.1.2" buildToolsVersion "23.0.2"
defaultConfig { defaultConfig {
minSdkVersion 9 minSdkVersion 9
targetSdkVersion 22 targetSdkVersion 23
versionCode 3 versionCode 4
versionName "0.7.3" versionName "0.7.4"
} }
buildTypes { buildTypes {
} }
...@@ -22,7 +22,7 @@ android { ...@@ -22,7 +22,7 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.3@aar') { compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4@aar') {
transitive = true transitive = true
} }
} }
......
package com.cedarstudios.cedarmapssdk; package com.cedarstudios.cedarmapssdk;
import android.util.Pair;
import com.cedarstudios.cedarmapssdk.auth.OAuth2Support; import com.cedarstudios.cedarmapssdk.auth.OAuth2Support;
import com.mapbox.mapboxsdk.geometry.LatLng;
import org.json.JSONObject; import org.json.JSONObject;
public interface CedarMaps extends OAuth2Support, CedarMapsBase { public interface CedarMaps extends OAuth2Support, CedarMapsBase {
/**
* Forward Geocoding. This API call needs a valid access token.
*
* @param searchTerm Wherever you want to get info about
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject geocode(String searchTerm) throws CedarMapsException; JSONObject geocode(String searchTerm) throws CedarMapsException;
JSONObject geocode(String searchTerm, String city) throws CedarMapsException; /**
* Forward Geocoding. This API call needs a valid access token.
*
* @param searchTerm Wherever you want to get info about
* @param type Possible values are: locality, roundabout, street, freeway, expressway, boulevard (You can mix types by separating them with ",")
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject geocode(String searchTerm, String type) throws CedarMapsException;
/**
* Forward Geocoding. This API call needs a valid access token.
*
* @param searchTerm Wherever you want to get info about
* @param type Possible values are: locality, roundabout, street, freeway, expressway, boulevard (You can mix types by separating them with ",")
* @param limit Number of results
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject geocode(String searchTerm, String type, int limit) throws CedarMapsException;
/**
* Forward Geocoding. This API call needs a valid access token.
*
* @param searchTerm Wherever you want to get info about
* @param location Center point. should be accompanied with distance param
* @param distance Distance from location. Unit is km, 0.1 means 100 meters
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject geocode(String searchTerm, LatLng location, float distance) throws CedarMapsException;
/**
* Forward Geocoding. This API call needs a valid access token.
*
* @param searchTerm Wherever you want to get info about
* @param location Center point. should be accompanied with distance param
* @param distance Distance from location. Unit is km, 0.1 means 100 meters
* @param type Possible values are: locality, roundabout, street, freeway, expressway, boulevard (You can mix types by separating them with ",")
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject geocode(String searchTerm, LatLng location, float distance, String type) throws CedarMapsException;
JSONObject geocode(String searchTerm, String city, double lat, double lng) /**
throws CedarMapsException; * Forward Geocoding. This API call needs a valid access token.
*
* @param searchTerm Wherever you want to get info about
* @param location Center point. should be accompanied with distance param
* @param distance Distance from location. Unit is km, 0.1 means 100 meters
* @param type Possible values are: locality, roundabout, street, freeway, expressway, boulevard (You can mix types by separating them with ",")
* @param limit Number of results
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject geocode(String searchTerm, LatLng location, float distance, String type, int limit) throws CedarMapsException;
JSONObject geocode(String searchTerm, String city, double lat, double lng, long distance)
throws CedarMapsException;
JSONObject geocode(String searchTerm, String city, double lat, double lng, long distance, /**
int limit) throws CedarMapsException; * Forward Geocoding. This API call needs a valid access token.
*
* @param searchTerm Wherever you want to get info about
* @param location Center point. should be accompanied with distance param
* @param distance Distance from location. Unit is km, 0.1 means 100 meters
* @param ne Specifies north east of the bounding box - should be accompanied with sw param
* @param sw Specifies south west of the bounding box - should be accompanied with ne param
* @param type Possible values are: locality, roundabout, street, freeway, expressway, boulevard (You can mix types by separating them with ",")
* @param limit Number of results
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject geocode(String searchTerm, LatLng location, float distance, LatLng ne, LatLng sw, String type, int limit) throws CedarMapsException;
/**
* Gives an address based on a provided LatLng pair. This API call needs a valid access token.
*
* @param lat
* @param lng
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject geocode(double lat, double lng) throws CedarMapsException; JSONObject geocode(double lat, double lng) throws CedarMapsException;
/**
* This method calculates the distance between points in meters. It can be called with up to 50 different points in a single request.
* This API call needs a valid access token.
*
* @param location1 Starting point
* @param location2 Ending point
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject distance(LatLng location1, LatLng location2) throws CedarMapsException;
/**
* This method calculates the distance between points in meters. It can be called with up to 15 pairs
* This API call needs a valid access token.
*
* @param locationPairs Set up to 15 pairs
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject distance(Pair<LatLng, LatLng>[] locationPairs) throws CedarMapsException;
/**
* Gives all localities in a city wih geometry in GeoJSON format.
* @param city City name in English or Persian
* @return Results as JSONObject
* @throws CedarMapsException
*/
JSONObject locality(String city) throws CedarMapsException;
} }
package com.cedarstudios.cedarmapssdk; package com.cedarstudios.cedarmapssdk;
import android.text.TextUtils;
import android.util.Pair;
import com.cedarstudios.cedarmapssdk.auth.Authorization; import com.cedarstudios.cedarmapssdk.auth.Authorization;
import com.cedarstudios.cedarmapssdk.auth.NullAuthorization; import com.cedarstudios.cedarmapssdk.auth.NullAuthorization;
import com.cedarstudios.cedarmapssdk.auth.OAuth2Authorization; import com.cedarstudios.cedarmapssdk.auth.OAuth2Authorization;
import com.cedarstudios.cedarmapssdk.config.Configuration; import com.cedarstudios.cedarmapssdk.config.Configuration;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request; import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response; import com.squareup.okhttp.Response;
...@@ -11,8 +15,6 @@ import com.squareup.okhttp.Response; ...@@ -11,8 +15,6 @@ import com.squareup.okhttp.Response;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.text.TextUtils;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Locale; import java.util.Locale;
...@@ -30,30 +32,37 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps { ...@@ -30,30 +32,37 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps {
} }
@Override @Override
public JSONObject geocode(String searchTerm, String city) throws CedarMapsException { public JSONObject geocode(String searchTerm, String type) throws CedarMapsException {
return geocode(searchTerm, city, Double.NaN, Double.NaN); return geocode(searchTerm, type, 30);
} }
@Override @Override
public JSONObject geocode(String searchTerm, String city, double lat, double lng) public JSONObject geocode(String searchTerm, String type, int limit) throws CedarMapsException {
throws CedarMapsException { return geocode(searchTerm, null, -1, null, null, type, limit);
return geocode(searchTerm, city, lat, lng, -1);
} }
@Override @Override
public JSONObject geocode(String searchTerm, String city, double lat, double lng, public JSONObject geocode(String searchTerm, LatLng location, float distance) throws CedarMapsException {
long distance) throws CedarMapsException { return geocode(searchTerm, location, distance, null, null, null, 30);
return geocode(searchTerm, city, lat, lng, distance, 30);
} }
@Override @Override
public JSONObject geocode(String searchTerm, String city, double lat, double lng, public JSONObject geocode(String searchTerm, LatLng location, float distance, String type) throws CedarMapsException {
long distance, int limit) throws CedarMapsException { return geocode(searchTerm, location, distance, null, null, type, 30);
}
@Override
public JSONObject geocode(String searchTerm, LatLng location, float distance, String type, int limit) throws CedarMapsException {
return geocode(searchTerm, location, distance, null, null, type, limit);
}
@Override
public JSONObject geocode(String searchTerm, LatLng location, float distance, LatLng ne, LatLng sw, String type, int limit)
throws CedarMapsException {
String term; String term;
if (TextUtils.isEmpty(conf.getMapId())) { if (TextUtils.isEmpty(conf.getMapId())) {
throw new CedarMapsException(new NullPointerException( throw new CedarMapsException(new NullPointerException("mapId is null. please provide a mapId in configuration"));
"mapId is null. please provide a mapId in configuration"));
} }
try { try {
...@@ -61,20 +70,24 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps { ...@@ -61,20 +70,24 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps {
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new CedarMapsException(e); throw new CedarMapsException(e);
} }
String url = String String url = String.format(Locale.ENGLISH, conf.getAPIBaseURL() + "geocode/%s/%s.json", conf.getMapId(), term);
.format(Locale.ENGLISH, conf.getAPIBaseURL() + "geocode/%s/%s.json",
conf.getMapId(), term);
url += String.format(Locale.ENGLISH, "?limit=%s", limit); url += String.format(Locale.ENGLISH, "?limit=%s", limit);
if (!TextUtils.isEmpty(city)) { if (location != null) {
url += String.format(Locale.ENGLISH, "&city=%s", city); url += String.format(Locale.ENGLISH, "&location=%1$s,%2$s&distance=%3$s", location.getLatitude(), location.getLongitude(), distance);
}
if (ne != null) {
url += String.format(Locale.ENGLISH, "&ne=%1$s,%2$s", ne.getLatitude(), ne.getLongitude());
} }
if (!Double.valueOf(lat).isNaN() && !Double.valueOf(lng).isNaN()) {
url += String.format(Locale.ENGLISH, "&location=%1$s,%2$s", lat, lng); if (sw != null) {
url += String.format(Locale.ENGLISH, "&sw=%1$s,%2$s", sw.getLatitude(), sw.getLongitude());
} }
if (distance != -1) {
url += String.format(Locale.ENGLISH, "&distance=%s", distance); if (!TextUtils.isEmpty(type)) {
url += String.format(Locale.ENGLISH, "&type=%s", type);
} }
try { try {
...@@ -87,14 +100,62 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps { ...@@ -87,14 +100,62 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps {
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
@Override @Override
public JSONObject geocode(double lat, double lng) throws CedarMapsException { public JSONObject geocode(double lat, double lng) throws CedarMapsException {
String url = String.format(Locale.ENGLISH, if (TextUtils.isEmpty(conf.getMapId())) {
conf.getAPIBaseURL() + "geocode/%1$s/%2$s,%3$s.json", conf.getMapId(), lat, lng); throw new CedarMapsException(new NullPointerException("mapId is null. please provide a mapId in configuration"));
}
String url = String.format(Locale.ENGLISH, conf.getAPIBaseURL() + "geocode/%1$s/%2$s,%3$s.json", conf.getMapId(), lat, lng);
try {
return new JSONObject(getDataFromAPI(url));
} catch (JSONException e) {
throw new CedarMapsException(e);
}
}
@Override
public JSONObject distance(LatLng location1, LatLng location2) throws CedarMapsException {
if (TextUtils.isEmpty(conf.getMapId())) {
throw new CedarMapsException(new NullPointerException("mapId is null. please provide a mapId in configuration"));
}
String url = String.format(Locale.ENGLISH, conf.getAPIBaseURL() + "distance/%1$s/%2$s,%3$s;%4$s,%5$s", conf.getMapId(),
location1.getLatitude(), location1.getLongitude(), location2.getLatitude(), location2.getLongitude());
try {
return new JSONObject(getDataFromAPI(url));
} catch (JSONException e) {
throw new CedarMapsException(e);
}
}
@Override
public JSONObject distance(Pair<LatLng, LatLng>[] locationPairs) throws CedarMapsException {
if (TextUtils.isEmpty(conf.getMapId())) { if (TextUtils.isEmpty(conf.getMapId())) {
throw new CedarMapsException(new NullPointerException( throw new CedarMapsException(new NullPointerException("mapId is null. please provide a mapId in configuration"));
"mapId is null. please provide a mapId in configuration"));
} }
String pairs = "";
String delimiter = "";
for (Pair<LatLng, LatLng> locationPair : locationPairs) {
pairs += delimiter + String.format(Locale.ENGLISH, "%1$s,%2$s;%3$s,%4$s", locationPair.first.getLatitude(),
locationPair.first.getLongitude(), locationPair.second.getLatitude(), locationPair.second.getLatitude());
delimiter = "/";
}
String url = String.format(Locale.ENGLISH, conf.getAPIBaseURL() + "distance/%1$s/%2$s", conf.getMapId(), pairs);
try {
return new JSONObject(getDataFromAPI(url));
} catch (JSONException e) {
throw new CedarMapsException(e);
}
}
@Override
public JSONObject locality(String city) throws CedarMapsException {
String url = String.format(Locale.ENGLISH, conf.getAPIBaseURL() + "locality/%s.json", city);
try { try {
return new JSONObject(getDataFromAPI(url)); return new JSONObject(getDataFromAPI(url));
} catch (JSONException e) { } catch (JSONException e) {
......
...@@ -3,6 +3,7 @@ package com.cedarstudios.cedarmaps.sample; ...@@ -3,6 +3,7 @@ package com.cedarstudios.cedarmaps.sample;
public class Constants { public class Constants {
public static final String MAPID_CEDARMAPS_STREETS = "cedarmaps.streets"; public static final String MAPID_CEDARMAPS_STREETS = "cedarmaps.streets";
public static final String MAPID_CEDARMAPS_DRIVING = "cedarmaps.driving";
public static final String CLIENT_ID = ""; public static final String CLIENT_ID = "";
public static final String CLIENT_SECRET = ""; public static final String CLIENT_SECRET = "";
} }
package com.cedarstudios.cedarmaps.sample.fragment; package com.cedarstudios.cedarmaps.sample.fragment;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.cedarstudios.cedarmaps.sample.Constants; import com.cedarstudios.cedarmaps.sample.Constants;
import com.cedarstudios.cedarmaps.sample.MainActivity; import com.cedarstudios.cedarmaps.sample.MainActivity;
import com.cedarstudios.cedarmaps.sample.R; import com.cedarstudios.cedarmaps.sample.R;
...@@ -18,23 +35,6 @@ import com.mapbox.mapboxsdk.views.MapView; ...@@ -18,23 +35,6 @@ import com.mapbox.mapboxsdk.views.MapView;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
public class APIAdvancedGeocodeTestFragment extends Fragment implements View.OnClickListener { public class APIAdvancedGeocodeTestFragment extends Fragment implements View.OnClickListener {
...@@ -47,7 +47,7 @@ public class APIAdvancedGeocodeTestFragment extends Fragment implements View.OnC ...@@ -47,7 +47,7 @@ public class APIAdvancedGeocodeTestFragment extends Fragment implements View.OnC
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_search, container, false); final View view = inflater.inflate(R.layout.fragment_search, container, false);
mapView = (MapView) view.findViewById(R.id.mapView); mapView = (MapView) view.findViewById(R.id.mapView);
...@@ -139,8 +139,8 @@ public class APIAdvancedGeocodeTestFragment extends Fragment implements View.OnC ...@@ -139,8 +139,8 @@ public class APIAdvancedGeocodeTestFragment extends Fragment implements View.OnC
.build(); .build();
CedarMaps cedarMaps = new CedarMapsFactory(configuration).getInstance(); CedarMaps cedarMaps = new CedarMapsFactory(configuration).getInstance();
searchResult = cedarMaps.geocode(params[0], "tehran", 35.6961, 51.4231, 3000, LatLng location = new LatLng(35.6961, 51.4231);
5); searchResult = cedarMaps.geocode(params[0], location, 50, null, 5);
} catch (CedarMapsException e) { } catch (CedarMapsException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -160,28 +160,19 @@ public class APIAdvancedGeocodeTestFragment extends Fragment implements View.OnC ...@@ -160,28 +160,19 @@ public class APIAdvancedGeocodeTestFragment extends Fragment implements View.OnC
JSONArray array = jsonObject.getJSONArray("results"); JSONArray array = jsonObject.getJSONArray("results");
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
JSONObject item = array.getJSONObject(i); JSONObject item = array.getJSONObject(i);
String[] location = item.getJSONObject("location").getString("center") String[] location = item.getJSONObject("location").getString("center").split(",");
.split(","); LatLng latLng = new LatLng(Double.parseDouble(location[0]), Double.parseDouble(location[1]));
LatLng latLng = new LatLng(Double.parseDouble(location[0]),
Double.parseDouble(location[1]));
Marker marker = new Marker(mapView, item.getString("name"), "", latLng); Marker marker = new Marker(mapView, item.getString("name"), "", latLng);
marker.setIcon( marker.setIcon(new Icon(getActivity(), Icon.Size.MEDIUM, "marker-stroked", "FF0000"));
new Icon(getActivity(), Icon.Size.MEDIUM, "marker-stroked",
"FF0000"));
mapView.addMarker(marker); mapView.addMarker(marker);
} }
} else if (status.equals("ZERO_RESULTS")) { } else if (status.equals("ZERO_RESULTS")) {
Toast.makeText(getActivity(), getString(R.string.no_results), Toast.makeText(getActivity(), getString(R.string.no_results), Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG)
.show();
} else { } else {
Toast.makeText(getActivity(), getString(R.string.unkonown_error), Toast.makeText(getActivity(), getString(R.string.unkonown_error), Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG)
.show();
} }
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(getActivity(), getString(R.string.parse_error), Toast.makeText(getActivity(), getString(R.string.parse_error), Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG).show();
} }
} }
} }
......
package com.cedarstudios.cedarmaps.sample.fragment; package com.cedarstudios.cedarmaps.sample.fragment;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.cedarstudios.cedarmaps.sample.Constants; import com.cedarstudios.cedarmaps.sample.Constants;
import com.cedarstudios.cedarmaps.sample.MainActivity; import com.cedarstudios.cedarmaps.sample.MainActivity;
import com.cedarstudios.cedarmaps.sample.R; import com.cedarstudios.cedarmaps.sample.R;
...@@ -18,23 +35,6 @@ import com.mapbox.mapboxsdk.views.MapView; ...@@ -18,23 +35,6 @@ import com.mapbox.mapboxsdk.views.MapView;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
public class APIGeocodeTestFragment extends Fragment implements View.OnClickListener { public class APIGeocodeTestFragment extends Fragment implements View.OnClickListener {
...@@ -47,7 +47,7 @@ public class APIGeocodeTestFragment extends Fragment implements View.OnClickList ...@@ -47,7 +47,7 @@ public class APIGeocodeTestFragment extends Fragment implements View.OnClickList
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_search, container, false); final View view = inflater.inflate(R.layout.fragment_search, container, false);
mapView = (MapView) view.findViewById(R.id.mapView); mapView = (MapView) view.findViewById(R.id.mapView);
...@@ -92,8 +92,7 @@ public class APIGeocodeTestFragment extends Fragment implements View.OnClickList ...@@ -92,8 +92,7 @@ public class APIGeocodeTestFragment extends Fragment implements View.OnClickList
if (!TextUtils.isEmpty(mSearchEditText.getText().toString())) { if (!TextUtils.isEmpty(mSearchEditText.getText().toString())) {
InputMethodManager inputManager = (InputMethodManager) getActivity() InputMethodManager inputManager = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE); .getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
InputMethodManager.HIDE_NOT_ALWAYS);
clearMarkers(); clearMarkers();
...@@ -130,8 +129,7 @@ public class APIGeocodeTestFragment extends Fragment implements View.OnClickList ...@@ -130,8 +129,7 @@ public class APIGeocodeTestFragment extends Fragment implements View.OnClickList
JSONObject searchResult = null; JSONObject searchResult = null;
try { try {
SharedPreferences pref = getActivity().getSharedPreferences(MainActivity.PREF_NAME, SharedPreferences pref = getActivity().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE);
Context.MODE_PRIVATE);
Configuration configuration = new ConfigurationBuilder() Configuration configuration = new ConfigurationBuilder()
.setOAuth2AccessToken(pref.getString(MainActivity.PREF_ID_ACCESS_TOKEN, "")) .setOAuth2AccessToken(pref.getString(MainActivity.PREF_ID_ACCESS_TOKEN, ""))
......
...@@ -16,7 +16,7 @@ repositories { ...@@ -16,7 +16,7 @@ repositories {
} }
dependencies { dependencies {
compile('com.cedarmaps:CedarMapsSDK:0.7.3@aar') { compile('com.cedarmaps:CedarMapsSDK:0.7.4@aar') {
transitive = true transitive = true
} }
} }
...@@ -76,8 +76,8 @@ To add the `MapView` as a layout element, add the following to your xml file: ...@@ -76,8 +76,8 @@ To add the `MapView` as a layout element, add the following to your xml file:
```xml ```xml
<com.mapbox.mapboxsdk.views.MapView <com.mapbox.mapboxsdk.views.MapView
android:id="@+id/mapView" android:id="@+id/mapView"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" /> android:layout_height="match_parent" />
``` ```
...@@ -228,7 +228,7 @@ com.cedarstudios.cedarmapssdk.config.Configuration ...@@ -228,7 +228,7 @@ com.cedarstudios.cedarmapssdk.config.Configuration
Then you should use `oAuth2Token` with each API call Then you should use `oAuth2Token` with each API call
#### Geocode (Street Search) #### Geocode (Place Search)
For finding a street you can easily call streetSearch method. For finding a street you can easily call streetSearch method.
...@@ -248,42 +248,55 @@ The output would be something like this for search term "همت": ...@@ -248,42 +248,55 @@ The output would be something like this for search term "همت":
{ {
"results": [ "results": [
{ {
"address": "المهدی", "address": "اراضی عباس آباد,مهران,سید خندان,...",
"id": 301568, "components": {
"location": { "city": "تهران",
"bb": { "country": "ایران",
"ne": "35.770861600000003,51.323841700000003", "districts": [
"sw": "35.770540400000002,51.323066400000002" "منطقه 4",
}, "منطقه 3"
"center": "35.770585227006897,51.323426168064202" ],
"localities": [
"اراضی عباس آباد",
"مهران",
"سید خندان",
"پاسداران"
],
"province": "تهران"
}, },
"name": "همت", "id": 429874,
"type": "street"
},
{
"address": "کاظم آباد,مهران,اراضی عباس آباد,...",
"id": 397432,
"location": { "location": {
"bb": { "bb": {
"ne": "35.759246099999999,51.4836156", "ne": "35.756689799999997,51.464761500000002",
"sw": "35.7491463,51.423702800000001" "sw": "35.7491463,51.423702800000001"
}, },
"center": "35.749153889854,51.427947792189102" "center": "35.749155599171999,51.428327751596903"
}, },
"name": "همت", "name": "همت",
"type": "expressway" "type": "expressway"
}, },
{ {
"address": "ابوذر,شهرابی", "address": "المهدی",
"id": 312434, "components": {
"city": "تهران",
"country": "ایران",
"districts": [
"منطقه 5"
],
"localities": [
"المهدی"
],
"province": "تهران"
},
"id": 338756,
"location": { "location": {
"bb": { "bb": {
"ne": "35.679308300000002,51.480144099999997", "ne": "35.770861600000003,51.323841700000003",
"sw": "35.679143099999997,51.478227199999999" "sw": "35.770540400000002,51.323066400000002"
}, },
"center": "35.679225700000003,51.479185649999998" "center": "35.770585227006897,51.323426168064202"
}, },
"name": "همتی", "name": "همت",
"type": "street" "type": "street"
} }
], ],
...@@ -306,36 +319,194 @@ CedarMaps cedarMaps = new CedarMapsFactory(configuration).getInstance(); ...@@ -306,36 +319,194 @@ CedarMaps cedarMaps = new CedarMapsFactory(configuration).getInstance();
searchResult = cedarMaps.geocode(lat, lng); searchResult = cedarMaps.geocode(lat, lng);
``` ```
The output would be something like this for 35.4,52.3: The output would be something like this for 35.716482704636825, 51.40897750854492:
```json ```json
{ {
"result": { "result": {
"address": "تهران، شهرک غرب، خیابان دادمان، خیابان سپهر", "address": "بن بست سروش - زرتشت",
"city": "تهران", "city": "تهران",
"components": [ "components": [
{ {
"long_name": "خیابان سپهر", "long_name": "بن بست سروش",
"short_name": "سپهر", "short_name": "بن بست سروش",
"type": "street" "type": "residential"
}, },
{ {
"long_name": "خیابان دادمان", "long_name": "زرتشت",
"short_name": "دادمان", "short_name": "زرتشت",
"type": "steet" "type": "primary"
}, },
{ {
"long_name": "شهرک غرب", "long_name": "بهجت آباد",
"short_name": "شهرک غرب", "short_name": "بهجت آباد",
"type": "locality" "type": "locality"
},
{
"long_name": "تهران",
"short_name": "تهران",
"type": "city"
} }
], ],
"locality": "شهرک غرب" "locality": "بهجت آباد",
"traffic_zone": {
"in_central": true,
"in_evenodd": true,
"name": "محدوده طرح ترافیک"
}
}, },
"status": "OK" "status": "OK"
} }
``` ```
#### Distance
This method calculates the distance between points in meters. It can be called with up to 50 different points in a single request.
The only supported profile is cedarmaps.driving which calculates the distance using car routing.
```java
Configuration configuration = new ConfigurationBuilder()
.setOAuth2AccessToken(oAuth2Token.getAccessToken())
.setOAuth2TokenType(oAuth2Token.getTokenType())
.setMapId(Constants.MAPID_CEDARMAPS_DRIVING)
.build();
CedarMaps cedarMaps = new CedarMapsFactory(configuration).getInstance();
searchResult = cedarMaps.distance(new LatLng(35.6961, 51.4231), new LatLng(35.744625, 51.374600));
```
Response elements:
distance: The overall distance of the route, in meter
time: The overall time of the route, in ms
bbox: The bounding box of the route, format: minLon, minLat, maxLon, maxLat
The output would be something like this:
```json
{
"result": {
"routes": [
{
"bbox": [
51.368587,
35.74982,
51.41652,
35.762383
],
"distance": 7516.338,
"time": 500912
}
]
},
"status": "OK"
}
```
#### Locality
It gives you all localities in a city wih geometry in GeoJSON format. This API call needs a valid access token.
```java
Configuration configuration = new ConfigurationBuilder()
.setOAuth2AccessToken(oAuth2Token.getAccessToken())
.setOAuth2TokenType(oAuth2Token.getTokenType())
.build();
CedarMaps cedarMaps = new CedarMapsFactory(configuration).getInstance();
searchResult = cedarMaps.locality("tehran");
```
Supported cities are: tehran, تهران
The output would be something like this:
```json
{
"results":
[
{
"geometry": {
"coordinates": [
[
[
51.3904371,
35.6144373
],
[
51.3860088,
35.6143914
],
[
51.3896979,
35.6169901
],
[
51.3893829,
35.6216496
],
[
51.3869264,
35.622008
],
[
51.3863595,
35.6257456
],
[
51.384092,
35.6256944
],
[
51.38384,
35.6281007
],
[
51.3821393,
35.6281007
],
[
51.378927,
35.6348585
],
[
51.378602,
35.6384921
],
[
51.3822129,
35.6370245
],
[
51.385588,
35.637117
],
[
51.3859658,
35.6313776
],
[
51.3916527,
35.6247423
],
[
51.3904371,
35.6144373
]
]
],
"type": "Polygon"
},
"name": "اسفندیاری و بستان"
}
],
"status": "OK"
}
```
### More Examples Via TestApp ### More Examples Via TestApp
The CedarMaps Android SDK is actually an [Android Library Module](https://developer.android.com/tools/projects/index.html#LibraryModules), The CedarMaps Android SDK is actually an [Android Library Module](https://developer.android.com/tools/projects/index.html#LibraryModules),
......
...@@ -5,8 +5,8 @@ buildscript { ...@@ -5,8 +5,8 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:1.2.3' classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.github.dcendents:android-maven-plugin:1.2' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
...@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME ...@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment