gpt4 book ai didi

java - 根据servlet中当前位置获取附近的纬度和经度

转载 作者:行者123 更新时间:2023-12-01 12:29:08 27 4
gpt4 key购买 nike

实际上我正在从 Android 设备获取当前纬度和经度的值。因此,根据当前位置,我必须发送附近的纬度和经度。请给我一些建议,以便我可以在我的项目中使用它。

最佳答案

您可以通过输入邮政编码来获取附近的经度和纬度:

public static void main(String[] args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter a postcode:");
String postcode=reader.readLine();
StringBuffer input=new StringBuffer();
String data=null;
String latLong=null;
String link="http://maps.google.com/maps?q="+URLEncoder.encode(postcode, "UTF-8");
URL url=new URL(link);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
BufferedReader br=new BufferedReader(new InputStreamReader(connection.getInputStream()));
if(connection.getResponseCode()==200)
{
System.out.println("Success");
while((data=br.readLine())!=null)
input.append(data);
}
int x=input.indexOf("lat:");
int y=input.indexOf("}",x);
latLong=input.substring(x,y);
latLong=latLong.replaceAll("lat:","");
latLong=latLong.replaceAll("lng:","");
System.out.println(latLong);
String[] array=latLong.split(",");
System.out.println("Latitude: "+array[0]+" and Longitude: "+array[1]+" for "+an>+postcode);
}

参见this教程。

关于java - 根据servlet中当前位置获取附近的纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26092489/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com