您好,登錄后才能下訂單哦!
例如:經度:10.123456 緯度:20.654321
根據以上坐標獲取到實際位置(不借用百度地圖或高德地圖的API)
代碼如下:
//放入經緯度就可以了 public String getAddress(double latitude, double longitude) { Geocoder geocoder = new Geocoder(this, Locale.getDefault()); try { List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) { Address address = addresses.get(0); String data = address.toString(); int startCity = data.indexOf("1:\"") + "1:\"".length(); int endCity = data.indexOf("\"", startCity); String city = data.substring(startCity, endCity); int startPlace = data.indexOf("feature=") + "feature=".length(); int endplace = data.indexOf(",", startPlace); String place = data.substring(startPlace, endplace); return city + place ; } } catch (IOException e) { e.printStackTrace(); } return "獲取失敗"; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。