【问题标题】:Get nearby latitude and longitude based on current location in servlet根据servlet中的当前位置获取附近的经纬度
【发布时间】:2014-11-23 09:48:22
【问题描述】:

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

【问题讨论】:

    标签: java html sql servlets


    【解决方案1】:

    您可以通过输入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中如何获取当前位置的经纬度?没有传递任何输入。如果可能,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 2013-01-11
    • 2011-04-11
    相关资源
    最近更新 更多