地图模块代码更新3.0.0
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package com.autonavi.nge.search;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class SPCategories implements Parcelable, Serializable {
|
||||
private List<Pair<Integer, String>> categories;
|
||||
|
||||
|
||||
public SPCategories() {
|
||||
}
|
||||
|
||||
protected SPCategories(Parcel in) {
|
||||
}
|
||||
|
||||
public static final Creator<SPCategories> CREATOR = new Creator<SPCategories>() {
|
||||
@Override
|
||||
public SPCategories createFromParcel(Parcel in) {
|
||||
return new SPCategories(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPCategories[] newArray(int size) {
|
||||
return new SPCategories[size];
|
||||
}
|
||||
};
|
||||
|
||||
public List<Pair<Integer, String>> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void setCategories(List<Pair<Integer, String>> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SPCategories{" +
|
||||
"categories=" + categories +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.autonavi.nge.search;
|
||||
|
||||
public final class SPConstants {
|
||||
// 语言码
|
||||
public static int LANGUAGE_CODE_ZH_CN = 31;
|
||||
public static int LANGUAGE_CODE_EN = 182;
|
||||
|
||||
// 检索关键字的类型。NOTE: 注释的部分为暂时不支持的检索方式
|
||||
public static int SEARCH_TYPE_POI = 0;
|
||||
public static int SEARCH_TYPE_POI_NAME = 1;
|
||||
// public static int SEARCH_TYPE_POI_ADDRESS = 2;
|
||||
public static int SEARCH_TYPE_POI_TELEPHONE = 3;
|
||||
// public static int SEARCH_TYPE_POI_POSTCODE = 4;
|
||||
// public static int SEARCH_TYPE_ROAD = 5;
|
||||
// public static int SEARCH_TYPE_ROAD_NAME = 6;
|
||||
// public static int SEARCH_TYPE_CROSS_ROAD = 7;
|
||||
// public static int SEARCH_TYPE_ADMIN = 8;
|
||||
// public static int SEARCH_TYPE_FTS_BOUND = 9;
|
||||
// public static int SEARCH_TYPE_POI_BOUND = 10;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.autonavi.nge.search;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SPLatLonPoint implements Parcelable, Serializable {
|
||||
public float lat;
|
||||
public float lon;
|
||||
public SPLatLonPoint(float lat, float lon) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
}
|
||||
|
||||
public SPLatLonPoint(double lat, double lon) {
|
||||
this((float)lat,(float)lon);
|
||||
}
|
||||
|
||||
public SPLatLonPoint(int latE6, int lonE6) {
|
||||
this.lat = E6ToDMS(latE6);
|
||||
this.lon = E6ToDMS(lonE6);
|
||||
}
|
||||
|
||||
protected SPLatLonPoint(Parcel in) {
|
||||
lat = in.readFloat();
|
||||
lon = in.readFloat();
|
||||
}
|
||||
|
||||
public static final Creator<SPLatLonPoint> CREATOR = new Creator<SPLatLonPoint>() {
|
||||
@Override
|
||||
public SPLatLonPoint createFromParcel(Parcel in) {
|
||||
return new SPLatLonPoint(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPLatLonPoint[] newArray(int size) {
|
||||
return new SPLatLonPoint[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("(%.7f, %.7f)", lon, lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 E6 标准的经纬度转换成 DMS 标准
|
||||
* @param lonOrLat 经纬度
|
||||
*/
|
||||
private static float E6ToDMS(int lonOrLat) {
|
||||
return lonOrLat / 1e6f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeFloat(lat);
|
||||
dest.writeFloat(lon);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.autonavi.nge.search;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SPPoiItem implements Parcelable,Serializable {
|
||||
public int poiId;
|
||||
public int kind;
|
||||
public SPLatLonPoint location; // 经纬度
|
||||
public String title; // 名字
|
||||
public String snippet; // 地址
|
||||
public String tel; // 电话
|
||||
public String postcode; // 邮编
|
||||
|
||||
public SPPoiItem() {
|
||||
}
|
||||
|
||||
protected SPPoiItem(Parcel in) {
|
||||
poiId = in.readInt();
|
||||
kind = in.readInt();
|
||||
title = in.readString();
|
||||
snippet = in.readString();
|
||||
tel = in.readString();
|
||||
postcode = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<SPPoiItem> CREATOR = new Creator<SPPoiItem>() {
|
||||
@Override
|
||||
public SPPoiItem createFromParcel(Parcel in) {
|
||||
return new SPPoiItem(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPPoiItem[] newArray(int size) {
|
||||
return new SPPoiItem[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(poiId);
|
||||
dest.writeInt(kind);
|
||||
dest.writeString(title);
|
||||
dest.writeString(snippet);
|
||||
dest.writeString(tel);
|
||||
dest.writeString(postcode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SPPoiItem{" +
|
||||
"poiId=" + poiId +
|
||||
", kind=" + kind +
|
||||
", location=" + location +
|
||||
", title='" + title + '\'' +
|
||||
", snippet='" + snippet + '\'' +
|
||||
", tel='" + tel + '\'' +
|
||||
", postcode='" + postcode + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.autonavi.nge.search;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SPQuery implements Parcelable, Serializable {
|
||||
// 每页最多有多少个数据
|
||||
private static int PAGE_SIZE_LIMIT = 50;
|
||||
|
||||
// 检索关键字
|
||||
public String keyword = null;
|
||||
// 检索范围。通过指定范围即可获取某个点附近的poi
|
||||
public SPSearchBound bound = null;
|
||||
// 检索的类型
|
||||
public int searchType = SPConstants.SEARCH_TYPE_POI;
|
||||
// 分页大小
|
||||
public int pageSize = 10;
|
||||
// 0 表示从头开始。其他值,表示上一次查询结果里面 poiId 的最大值
|
||||
public int pageStart = 0;
|
||||
// 语种。(NOTE: 该参数目前为保留参数。修改也无实际效果)
|
||||
public int languageCode = SPConstants.LANGUAGE_CODE_ZH_CN;
|
||||
// 分类。0 表示不限制
|
||||
public int categoryId = 0;
|
||||
// 限制搜索的区域 null 表示全国,"北京市" 这样的表示指定城市,"昌平区,北京市" 这样的表示更具体的区级别指定
|
||||
// 在指定了 bound 的情况下,将忽略 region 参数
|
||||
public String region = null;
|
||||
|
||||
public SPQuery() {
|
||||
}
|
||||
|
||||
protected SPQuery(Parcel in) {
|
||||
keyword = in.readString();
|
||||
searchType = in.readInt();
|
||||
pageSize = in.readInt();
|
||||
pageStart = in.readInt();
|
||||
languageCode = in.readInt();
|
||||
categoryId = in.readInt();
|
||||
region = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<SPQuery> CREATOR = new Creator<SPQuery>() {
|
||||
@Override
|
||||
public SPQuery createFromParcel(Parcel in) {
|
||||
return new SPQuery(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPQuery[] newArray(int size) {
|
||||
return new SPQuery[size];
|
||||
}
|
||||
};
|
||||
|
||||
public boolean isValid() {
|
||||
if (bound != null && !bound.isValid()) return false;
|
||||
return (pageSize > 0 && pageSize <= PAGE_SIZE_LIMIT && pageStart >= 0 && !TextUtils.isEmpty(keyword));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(keyword);
|
||||
dest.writeInt(searchType);
|
||||
dest.writeInt(pageSize);
|
||||
dest.writeInt(pageStart);
|
||||
dest.writeInt(languageCode);
|
||||
dest.writeInt(categoryId);
|
||||
dest.writeString(region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SPQuery{" +
|
||||
"keyword='" + keyword + '\'' +
|
||||
", bound=" + bound +
|
||||
", searchType=" + searchType +
|
||||
", pageSize=" + pageSize +
|
||||
", pageStart=" + pageStart +
|
||||
", languageCode=" + languageCode +
|
||||
", categoryId=" + categoryId +
|
||||
", region='" + region + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package com.autonavi.nge.search;
|
||||
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SPSearchBound implements Parcelable, Serializable {
|
||||
protected SPSearchBound(Parcel in) {
|
||||
this.shape = NONE;
|
||||
points = null;
|
||||
}
|
||||
|
||||
public SPSearchBound() {
|
||||
this.shape = NONE;
|
||||
points = null;
|
||||
}
|
||||
|
||||
public static final Creator<SPSearchBound> CREATOR = new Creator<SPSearchBound>() {
|
||||
@Override
|
||||
public SPSearchBound createFromParcel(Parcel in) {
|
||||
return new SPSearchBound(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPSearchBound[] newArray(int size) {
|
||||
return new SPSearchBound[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
}
|
||||
|
||||
public static final int CIRCLE = 0;
|
||||
public static final int RECT = 1;
|
||||
public static final int POLYGON = 2;
|
||||
public static final int NONE = 3;
|
||||
|
||||
public final int shape;
|
||||
public final SPLatLonPoint[] points;
|
||||
|
||||
// 可以用来配置最大允许的检索范围上限
|
||||
// 目前建议不要超过 3000m 否则会对速度有影响
|
||||
public float maxDistance = 3000;
|
||||
|
||||
/**
|
||||
* 圆形检索。或者用于检索距离一个目标点附近的点并按距离排序
|
||||
* @param center
|
||||
* @param m 需要大于 0
|
||||
* @param isSortByDistance
|
||||
*/
|
||||
public SPSearchBound(@NonNull final SPLatLonPoint center, float m, boolean isSortByDistance) {
|
||||
this.shape = SPSearchBound.CIRCLE;
|
||||
points = new SPLatLonPoint[2];
|
||||
points[0] = center;
|
||||
points[1] = new SPLatLonPoint(m, isSortByDistance ? 1f : 0f);
|
||||
}
|
||||
|
||||
public SPSearchBound(@NonNull final SPLatLonPoint leftBottom, @NonNull final SPLatLonPoint rightTop) {
|
||||
this.shape = SPSearchBound.RECT;
|
||||
points = new SPLatLonPoint[2];
|
||||
points[0] = leftBottom;
|
||||
points[1] = rightTop;
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要是凸多边形
|
||||
* @param points
|
||||
*/
|
||||
public SPSearchBound(@NonNull final List<SPLatLonPoint> points) {
|
||||
this.shape = SPSearchBound.POLYGON;
|
||||
this.points = new SPLatLonPoint[points.size()];
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
this.points[i] = points.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判定参数是否有效。包含了最大点距离检测,是否为凸多边形
|
||||
* @return
|
||||
*/
|
||||
public boolean isValid() {
|
||||
switch (this.shape) {
|
||||
case SPSearchBound.CIRCLE:
|
||||
return isValidCircle();
|
||||
case SPSearchBound.RECT:
|
||||
return isValidRect();
|
||||
case SPSearchBound.POLYGON:
|
||||
return isValidPolygon();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过经纬度的差值求距离
|
||||
* @param deltaDegree
|
||||
* @return 距离单位为
|
||||
*/
|
||||
static public float getDistance(float deltaDegree) {
|
||||
return (40075e3f * deltaDegree) / 360;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一组点是否能组成凸多边形
|
||||
* @param points
|
||||
* @return
|
||||
*/
|
||||
static public boolean isConvexPolygon(@NonNull final SPLatLonPoint[] points) {
|
||||
int n = points.length;
|
||||
if (n < 3) return false;
|
||||
|
||||
// 先根据获取到的一个非0 向量叉积来定义点是顺是真还是逆时针的
|
||||
int dir = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
SPLatLonPoint a = points[i];
|
||||
SPLatLonPoint b = points[(i + 1) % n];
|
||||
SPLatLonPoint c = points[(i + 2) % n];
|
||||
|
||||
// 求叉积
|
||||
double t = (double)(a.lon - c.lon) * (double)(b.lat - c.lat) - (double)(b.lon - c.lon) * (double)(a.lat - c.lat);
|
||||
// 浮点数计算是有误差的。如果t的绝对值小于一个预订值,我们就认为他是0
|
||||
if (Math.abs(t) < 0.0000001) continue;
|
||||
// 定下来点排列的方向
|
||||
if (dir == 0) {
|
||||
// 三个点称顺时针排列
|
||||
if (t < 0) {
|
||||
dir = -1;
|
||||
} else {
|
||||
dir = 1;
|
||||
}
|
||||
}
|
||||
// 和第一组有顺逆时针方向的点趋势不一致的时候就可以断定非凸多边形
|
||||
if ((t * dir) < 0) return false;
|
||||
}
|
||||
return dir != 0;
|
||||
}
|
||||
|
||||
private boolean isValidCircle() {
|
||||
// 检测半径是否超了
|
||||
float r = points[1].lat;
|
||||
return r > 0 && r <= maxDistance;
|
||||
}
|
||||
|
||||
private boolean isValidRect() {
|
||||
// 判断点的位置是否正确
|
||||
SPLatLonPoint lb = points[0];
|
||||
SPLatLonPoint rt = points[1];
|
||||
if (lb.lat >= rt.lat || lb.lon >= rt.lon) return false;
|
||||
|
||||
// 判定距离是否合法
|
||||
float d2 = maxDistance + maxDistance;
|
||||
return getDistance(rt.lat - lb.lat) <= d2 && getDistance(rt.lon - lb.lon) <= d2;
|
||||
}
|
||||
|
||||
private boolean isValidPolygon() {
|
||||
// 先检测是否是凸多边形
|
||||
if (!isConvexPolygon(points)) return false;
|
||||
// 检测点和点之间的距离。作为最大允许的圆形范围的内接多边形检测距离
|
||||
double d22 = Math.pow(maxDistance + maxDistance, 2);
|
||||
for (int i = 0; i < points.length - 1; ++i) {
|
||||
SPLatLonPoint a = points[i];
|
||||
for (int j = i + 1; j < points.length; ++j) {
|
||||
SPLatLonPoint b = points[j];
|
||||
if (Math.pow((a.lat - b.lat), 2) + Math.pow((a.lon - b.lon), 2) > d22) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SPSearchBound{" +
|
||||
"shape=" + shape +
|
||||
", points=" + Arrays.toString(points) +
|
||||
", maxDistance=" + maxDistance +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.autonavi.nge.search;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class SPSearchResult implements Parcelable, Serializable {
|
||||
// poi 信息
|
||||
public SPPoiItem poi;
|
||||
// 排序用 ID
|
||||
public int orderId;
|
||||
|
||||
public SPSearchResult(SPPoiItem item, int orderId) {
|
||||
this.orderId = orderId;
|
||||
this.poi = item;
|
||||
}
|
||||
|
||||
protected SPSearchResult(Parcel in) {
|
||||
poi = in.readParcelable(SPPoiItem.class.getClassLoader());
|
||||
orderId = in.readInt();
|
||||
}
|
||||
|
||||
public static final Creator<SPSearchResult> CREATOR = new Creator<SPSearchResult>() {
|
||||
@Override
|
||||
public SPSearchResult createFromParcel(Parcel in) {
|
||||
return new SPSearchResult(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPSearchResult[] newArray(int size) {
|
||||
return new SPSearchResult[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeParcelable(poi, i);
|
||||
parcel.writeInt(orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SPSearchResult{" +
|
||||
"poi=" + poi +
|
||||
", orderId=" + orderId +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//package com.autonavi.nge.search
|
||||
//
|
||||
//import com.autonavi.nge.dm.NavigationCore
|
||||
//import com.autonavi.nge.dm.SharedMemoryService
|
||||
//import com.zhidaoauto.map.sdk.inner.controller.CommonController
|
||||
//
|
||||
//object SearchAutoApi {
|
||||
//
|
||||
// fun init(){
|
||||
// if(CommonController.instance.iNavigationCore == null){
|
||||
// CommonController.instance.iNavigationCore = NavigationCore(SharedMemoryService.getInstance())
|
||||
// }s
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,173 @@
|
||||
package com.autonavi.nge.search;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.zhidaoauto.map.sdk.inner.CompileConfig;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchProvider {
|
||||
|
||||
private static final String TAG = "SearchProvider";
|
||||
|
||||
{
|
||||
System.loadLibrary("datamgr");
|
||||
System.loadLibrary("search");
|
||||
}
|
||||
|
||||
public SearchProvider() {
|
||||
|
||||
if(CompileConfig.INSTANCE.getDEBUG()){
|
||||
Log.i(TAG, "searchop--SearchProvider load start");
|
||||
}
|
||||
load();
|
||||
if(CompileConfig.INSTANCE.getDEBUG()){
|
||||
Log.i(TAG, "searchop--SearchProvider load over");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化。使用所有接口前应先调用该接口
|
||||
*/
|
||||
public static void load() {
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放数据
|
||||
*/
|
||||
public static void unload() {
|
||||
release();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有分类列表。应在初始化的时候调用一次
|
||||
* @param languageCode SPConstants.LANGUAGE_CODE_xxx
|
||||
* @return 返回 categoryId, categoryName 组成的列表
|
||||
*/
|
||||
public synchronized static @Nullable
|
||||
List<Pair<Integer, String>> getAllPoiCategories(int languageCode) {
|
||||
byte[] data = queryAllPoiCategories(languageCode);
|
||||
return parseIntStrPairList(bytes2ByteBuffer(data));
|
||||
}
|
||||
|
||||
public synchronized static @Nullable List<SPSearchResult> getPoiItemList(@NonNull final SPQuery query) {
|
||||
// 参数检测
|
||||
if (!query.isValid()) {
|
||||
return null;
|
||||
}
|
||||
if (CompileConfig.INSTANCE.getDEBUG()) {
|
||||
Log.i(TAG, "searchop--getPoiItemList--start--"+query);
|
||||
}
|
||||
|
||||
byte[] data = queryPoiItemList(query);
|
||||
if (CompileConfig.INSTANCE.getDEBUG()) {
|
||||
Log.i(TAG, "searchop--getPoiItemList--end--"+Thread.currentThread().getId());
|
||||
}
|
||||
return parseSPSearchResultList(bytes2ByteBuffer(data));
|
||||
}
|
||||
|
||||
public synchronized static @Nullable SPPoiItem getPoiItemByPoiId(int poiId) {
|
||||
byte[] data = queryPoiItemByPoiId(poiId);
|
||||
return parseSPPoiItem(bytes2ByteBuffer(data));
|
||||
}
|
||||
|
||||
/// private methods
|
||||
private static String buf2Str(final ByteBuffer buf) {
|
||||
int l = buf.getShort();
|
||||
String ret = null;
|
||||
if (l > 0) {
|
||||
byte[] tmp = new byte[l];
|
||||
for (int idx = 0; idx < l; idx++) {
|
||||
tmp[idx] = (byte) buf.get();
|
||||
}
|
||||
try {
|
||||
ret = new String(tmp, "UTF8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static ByteBuffer bytes2ByteBuffer(final byte[] data) {
|
||||
// 对数据进行格式化
|
||||
if (data == null || data.length < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ByteBuffer buf = ByteBuffer.wrap(data);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private static SPPoiItem parseSPPoiItem(final ByteBuffer buf) {
|
||||
if (buf == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SPPoiItem item = new SPPoiItem();
|
||||
item.poiId = buf.getInt();
|
||||
item.kind = buf.getInt();
|
||||
item.location = new SPLatLonPoint(buf.getInt(), buf.getInt());
|
||||
item.title = buf2Str(buf);
|
||||
item.snippet = buf2Str(buf);
|
||||
item.tel = buf2Str(buf);
|
||||
item.postcode = buf2Str(buf);
|
||||
return item;
|
||||
}
|
||||
|
||||
private static SPSearchResult parseSPSearchResult(final ByteBuffer buf) {
|
||||
SPPoiItem item = parseSPPoiItem(buf);
|
||||
if (item == null) return null;
|
||||
return new SPSearchResult(item, buf.getInt());
|
||||
}
|
||||
|
||||
private static List<SPSearchResult> parseSPSearchResultList(final ByteBuffer buf) {
|
||||
if (buf == null) {
|
||||
return null;
|
||||
}
|
||||
int itemCount = buf.getInt();
|
||||
|
||||
List<SPSearchResult> ret = new ArrayList<SPSearchResult>(itemCount);
|
||||
while (itemCount --> 0) {
|
||||
ret.add(parseSPSearchResult(buf));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static Pair<Integer, String> parseIntStrPair(final ByteBuffer buf) {
|
||||
if (buf == null) {
|
||||
return null;
|
||||
}
|
||||
return new Pair<Integer, String>(new Integer(buf.getInt()), buf2Str(buf));
|
||||
}
|
||||
|
||||
private static List<Pair<Integer, String>> parseIntStrPairList(final ByteBuffer buf) {
|
||||
if (buf == null) {
|
||||
return null;
|
||||
}
|
||||
int cnt = buf.getInt();
|
||||
|
||||
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>(cnt);
|
||||
while (cnt --> 0) {
|
||||
ret.add(parseIntStrPair(buf));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// native methods
|
||||
private static native boolean init();
|
||||
private static native void release();
|
||||
private static native byte[] queryPoiItemList(SPQuery query);
|
||||
private static native byte[] queryPoiItemByPoiId(int poiId);
|
||||
private static native byte[] queryAllPoiCategories(int languageCode);
|
||||
}
|
||||
Reference in New Issue
Block a user