【发布时间】:2014-11-23 09:48:22
【问题描述】:
实际上,我正在从 android 设备获取当前纬度和经度的值。因此,根据当前位置,我必须发送附近的纬度和经度。请给我一些建议,以便我可以在我的项目中使用它。
【问题讨论】:
实际上,我正在从 android 设备获取当前纬度和经度的值。因此,根据当前位置,我必须发送附近的纬度和经度。请给我一些建议,以便我可以在我的项目中使用它。
【问题讨论】:
您可以通过输入ZIP/Postal获取附近的Longitude & Latitude代码:
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 教程。
【讨论】: