本文介绍了如何从android中的城市名称获取经纬度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,将默认值设置为纬度经度
当我在edittext中键入 cityname 时,我需要将那个点移动到我需要的地方

In my application am setting a default value to latitude and longitude.When i type the cityname in edittext i need to move that point to that place where i need

推荐答案

使用下面的代码获取城市名称的经纬度和长度

Use the below code to get the lat and long of city name

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();
 }

这篇关于如何从android中的城市名称获取经纬度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:10