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

时间:2014-09-29 04:18:15

标签: java html sql servlets

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

1 个答案:

答案 0 :(得分:1)

您可以输入Longitude & Latitude代码

来附近ZIP/Postal
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教程。