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