如何获得城市/国家名称android的经纬度界限

时间:2017-09-20 04:00:19

标签: android google-maps

我在谷歌地图中搜索特定城市的纬度和经度范围。我得到了为国名India实施的例子。

private static final LatLngBounds BOUNDS_INDIA = new LatLngBounds(new LatLng(23.63936, 68.14712), new LatLng(28.20453, 97.34466));

现在,我想为我选择的国家设置它。哪里可以找到特定区域的两点纬度和经度。

1 个答案:

答案 0 :(得分:0)

检查以下代码

 String location=cityName;
String inputLine = "";
String result = ""
location=location.replaceAll(" ", "%20");
String myUrl="http://maps.google.com/maps/geo?q="+location+"&output=csv";
try{
 URL url=new URL(myUrl);
 URLConnection urlConnection=url.openConnection();
 BufferedReader in = new BufferedReader(new 
 InputStreamReader(urlConnection.getInputStream()));
  while ((inputLine = in.readLine()) != null) {
  result=inputLine;
  }
  String lat = result.substring(6, result.lastIndexOf(","));
  String longi = result.substring(result.lastIndexOf(",") + 1);
 }
 catch(Exception e){
 e.printStackTrace();
 }