0
其实我从android设备获取当前经纬度的值。所以根据当前位置我必须发送附近的经纬度。请给我一些建议,以便我可以在我的项目中使用它。根据当前在servlet中的位置获取附近的经度和纬度
其实我从android设备获取当前经纬度的值。所以根据当前位置我必须发送附近的经纬度。请给我一些建议,以便我可以在我的项目中使用它。根据当前在servlet中的位置获取附近的经度和纬度
您可以通过输入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教程。
user3145373ツ:如何在java中获取当前位置的经纬度?没有通过任何输入。如果可能的话,请让我知道。 – Prathyush 2015-06-03 12:26:23
你做完了吗? – 2014-09-29 04:50:05