本文目錄一覽:
怎樣在java中調用百度地圖的API
百度地圖Web服務API為開發者提供http介面,即開發者通過http形式發起檢索請求,獲取返回json或xml格式的檢索數據。
api官網說明鏈接:
1、可用介面列舉:
獲取相關地址提示 place suggestion
水杉®ion=成都output=jsonak=42b8ececa9cd6fe72ae4cddd77c0da5d
2、獲取坐標 geocoding
錦江區菱安路299號output=jsonkey=42b8ececa9cd6fe72ae4cddd77c0da5d
;output=jsonquery=藍光coco金沙page_size=10page_num=0scope=1®ion=成都
{
“status”:0,
“message”:”ok”,
“total”:2,
“results”:[
{
“name”:”藍光COCO金沙”,
“location”:{
“lat”:30.687544,
“lng”:103.996691
},
“address”:”西三環外金沙西源大道(IT大道旁)”,
“uid”:”223992992c5ee7e0841541df”
},
{
“name”:”藍光COCO金沙2期”,
“location”:{
“lat”:30.681123,
“lng”:103.991123
},
“address”:”青羊區金沙IT大道旁”,
“uid”:”b7bb5abb1cd4982213293580″
}
]
}
3、設施導航
;output=jsonquery=圖書館page_size=20page_num=0scope=2®ion=成都
4、java測試類:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
public class LocationUtil {
private static final String BAIDU_APP_KEY = “42b8ececa9cd6fe72ae4cddd77c0da5d”;
/**
* 返回輸入地址的經緯度坐標 key lng(經度),lat(緯度)
*/
public static MapString, String getLatitude(String address) {
try {
// 將地址轉換成utf-8的16進位
address = URLEncoder.encode(address, “UTF-8”);
// 如果有代理,要設置代理,沒代理可注釋
// System.setProperty(“http.proxyHost”,”192.168.172.23″);
// System.setProperty(“http.proxyPort”,”3209″);
URL resjson = new URL(“”
+ address + “output=jsonkey=” + BAIDU_APP_KEY);
BufferedReader in = new BufferedReader(new InputStreamReader(
resjson.openStream()));
String res;
StringBuilder sb = new StringBuilder(“”);
while ((res = in.readLine()) != null) {
sb.append(res.trim());
}
in.close();
String str = sb.toString();
System.out.println(“return json:” + str);
if(str!=null!str.equals(“”)){
MapString, String map = null;
int lngStart = str.indexOf(“lng\”:”);
int lngEnd = str.indexOf(“,\”lat”);
int latEnd = str.indexOf(“},\”precise”);
if (lngStart 0 lngEnd 0 latEnd 0) {
String lng = str.substring(lngStart + 5, lngEnd);
String lat = str.substring(lngEnd + 7, latEnd);
map = new HashMapString, String();
map.put(“lng”, lng);
map.put(“lat”, lat);
return map;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String args[]) {
MapString, String map = LocationUtil.getLatitude(“成都 高新西區西區大道1398號”);
if (null != map) {
System.out.println(map.get(“lng”));
System.out.println(map.get(“lat”));
}
}
}
java如何實現電子地圖的定位
CellInfoManager
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
public class CellInfoManager {
private int asu;
private int bid;
private int cid;
private boolean isCdma;
private boolean isGsm;
private int lac;
private int lat;
private final PhoneStateListener listener;
private int lng;
private int mcc;
private int mnc;
private int nid;
private int sid;
private TelephonyManager tel;
private boolean valid;
private Context context;
public CellInfoManager(Context paramContext) {
this.listener = new CellInfoListener(this);
tel = (TelephonyManager) paramContext.getSystemService(Context.TELEPHONY_SERVICE);
this.tel.listen(this.listener, PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_SIGNAL_STRENGTH);
context = paramContext;
}
public static int dBm(int i) {
int j;
if (i = 0 i = 31)
j = i * 2 + -113;
else
j = 0;
return j;
}
public int asu() {
return this.asu;
}
public int bid() {
if (!this.valid)
update();
return this.bid;
}
public JSONObject cdmaInfo() {
if (!isCdma()) {
return null;
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(“bid”, bid());
jsonObject.put(“sid”, sid());
jsonObject.put(“nid”, nid());
jsonObject.put(“lat”, lat());
jsonObject.put(“lng”, lng());
} catch (JSONException ex) {
jsonObject = null;
Log.e(“CellInfoManager”, ex.getMessage());
}
return jsonObject;
}
public JSONArray cellTowers() {
JSONArray jsonarray = new JSONArray();
int lat;
int mcc;
int mnc;
int aryCell[] = dumpCells();
lat = lac();
mcc = mcc();
mnc = mnc();
if (aryCell == null || aryCell.length 2) {
aryCell = new int[2];
aryCell[0] = cid;
aryCell[1] = -60;
}
for (int i = 0; i aryCell.length; i += 2) {
try {
int j2 = dBm(i + 1);
JSONObject jsonobject = new JSONObject();
jsonobject.put(“cell_id”, aryCell[i]);
jsonobject.put(“location_area_code”, lat);
jsonobject.put(“mobile_country_code”, mcc);
jsonobject.put(“mobile_network_code”, mnc);
jsonobject.put(“signal_strength”, j2);
jsonobject.put(“age”, 0);
jsonarray.put(jsonobject);
} catch (Exception ex) {
ex.printStackTrace();
Log.e(“CellInfoManager”, ex.getMessage());
}
}
if (isCdma())
jsonarray = new JSONArray();
return jsonarray;
}
public int cid() {
if (!this.valid)
update();
return this.cid;
}
public int[] dumpCells() {
int[] aryCells;
if (cid() == 0) {
aryCells = new int[0];
return aryCells;
}
ListNeighboringCellInfo lsCellInfo = this.tel.getNeighboringCellInfo();
if (lsCellInfo == null || lsCellInfo.size() == 0) {
aryCells = new int[1];
int i = cid();
aryCells[0] = i;
檢舉補充回答:
return aryCells;
}
int[] arrayOfInt1 = new int[lsCellInfo.size() * 2 + 2];
int j = 0 + 1;
int k = cid();
arrayOfInt1[0] = k;
int m = j + 1;
int n = asu();
arrayOfInt1[j] = n;
IteratorNeighboringCellInfo iter = lsCellInfo.iterator();
while (true) {
if (!iter.hasNext()) {
break;
}
NeighboringCellInfo localNeighboringCellInfo = (NeighboringCellInfo) iter.next();
int i2 = localNeighboringCellInfo.getCid();
if ((i2 = 0) || (i2 == 65535))
continue;
int i3 = m + 1;
arrayOfInt1[m] = i2;
m = i3 + 1;
int i4 = localNeighboringCellInfo.getRssi();
arrayOfInt1[i3] = i4;
}
int[] arrayOfInt2 = new int[m];
System.arraycopy(arrayOfInt1, 0, arrayOfInt2, 0, m);
aryCells = arrayOfInt2;
return aryCells;
}
public JSONObject gsmInfo() {
if (!isGsm()) {
return null;
}
JSONObject localObject = null;
while (true) {
try {
檢舉補充回答: JSONObject localJSONObject1 = new JSONObject();
String str1 = this.tel.getNetworkOperatorName();
localJSONObject1.put(“operator”, str1);
String str2 = this.tel.getNetworkOperator();
if ((str2.length() == 5) || (str2.length() == 6)) {
String str3 = str2.substring(0, 3);
String str4 = str2.substring(3, str2.length());
localJSONObject1.put(“mcc”, str3);
localJSONObject1.put(“mnc”, str4);
}
localJSONObject1.put(“lac”, lac());
int[] arrayOfInt = dumpCells();
JSONArray localJSONArray1 = new JSONArray();
int k = 0;
int m = arrayOfInt.length / 2;
while (true) {
if (k = m) {
localJSONObject1.put(“cells”, localJSONArray1);
localObject = localJSONObject1;
break;
}
int n = k * 2;
int i1 = arrayOfInt[n];
int i2 = k * 2 + 1;
int i3 = arrayOfInt[i2];
JSONObject localJSONObject7 = new JSONObject();
localJSONObject7.put(“cid”, i1);
localJSONObject7.put(“asu”, i3);
localJSONArray1.put(localJSONObject7);
k += 1;
}
} catch (JSONException localJSONException) {
localObject = null;
}
}
}
public boolean isCdma() {
if (!this.valid)
update();
如何使用java 開發百度地圖
百度有提供api的,一般是按照api給的網址,在網址後加經緯度或者地區名,但是百度地圖要申請秘鑰的,這個需要自己去申請一個,免費的,類似的功能你可以參考下面的源碼雖然是javascript的,但是java用起來差不多,畢竟你的地圖肯定是在web頁面顯示的
!DOCTYPE html
html
head
meta name=”viewport” content=”initial-scale=1.0, user-scalable=no” /
meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /
titleHello, World/title
style type=”text/css”
html{height:100%}
body{height:100%;margin:0px;padding:0px}
#container{height:100%}
/style
script type=”text/javascript” src=”;ak=您的密鑰”
//v2.0版本的引用方式:src=”;ak=您的密鑰”
//v1.4版本及以前版本的引用方式:src=”;key=您的密鑰callback=initialize”
/script
/head
body
div id=”container”/div
script type=”text/javascript”
var map = new BMap.Map(“container”); // 創建地圖實例
var point = new BMap.Point(116.404, 39.915); // 創建點坐標
map.centerAndZoom(point, 15); // 初始化地圖,設置中心點坐標和地圖級別
/script
/body
/html
java地圖著色問題
建議百度搜索地圖著色問題,這是一個數學問題,印象中應該是個圖的問題,所以你要先會用數學方式解決,其次才是用程序代碼描述出來。
我的世界java版地圖怎麼下載?
我的世界java版地圖可以到我的世界遊戲論壇下載。
《我的世界》是由Mojang Studios開發,在中國由網易代理的沙盒式建造遊戲,遊戲於2017年8月8日在中國大陸獨家運營。
遊戲著重於讓玩家去探索、交互、並且改變一個由一立方米大小的方塊動態生成的地圖。除了方塊以外,環境單體還包括植物、生物與物品。遊戲里的各種活動包括採集礦石、與敵對生物戰鬥、合成新的方塊與收集各種在遊戲中找到的資源的工具。
遊戲中的無限制模式讓玩家在各種多人遊戲伺服器或他們的單人模式中進行創造建築物、作品與藝術創作。其他功能包括邏輯運算與遠程動作的紅石電路、礦車及軌道,以及稱之為「下界」的神秘世界。最終可以選擇前往一個叫作「末路之地」的維度,並擊敗末影龍。
遊戲內容:
玩家們可以自由選擇遊戲模式 [生存、創造、冒險、極限 (僅Java版) 和旁觀模式(僅Java版) ]。在各種模式中體驗不一樣的有趣玩法,在生存模式中享受打怪、冒險等多種樂趣,在創造模式下享受當創世神的樂趣。該遊戲以玩家在三維空間中自由地創造和破壞不同種類的方塊為主題。
玩家在遊戲中可以在單人或多人模式中通過摧毀或創造精妙絕倫的建築物和藝術,或者收集物品探索地圖以完成遊戲的成就(進度)。玩家也可以嘗試紅石電路和指令等玩法。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/153946.html