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