Java 在谷歌地图中转换纬度和经度?
我正在创建一个应用程序,通过点击安卓手机上的一个按钮,我可以通过gps跟踪器设备来跟踪目标。在响应按钮时,单击gps设备,该设备包含sim卡响应,并显示其纬度和经度以及设备的速度。设备发送的消息将在我的手机的收件箱中接收。我想把纬度和经度转换成谷歌地图,或者至少转换成某种地址形式。有人能给我一个合适的方法或者给我一些提示吗?我认为有两种方法可能对你有用Java 在谷歌地图中转换纬度和经度?,java,android,android-emulator,Java,Android,Android Emulator,我正在创建一个应用程序,通过点击安卓手机上的一个按钮,我可以通过gps跟踪器设备来跟踪目标。在响应按钮时,单击gps设备,该设备包含sim卡响应,并显示其纬度和经度以及设备的速度。设备发送的消息将在我的手机的收件箱中接收。我想把纬度和经度转换成谷歌地图,或者至少转换成某种地址形式。有人能给我一个合适的方法或者给我一些提示吗?我认为有两种方法可能对你有用 使用您已经拥有的GPS坐标,打开地图,并将ap置于这些纵横坐标的中心 使用一些第三方api,它将为您提供纬度和经度的附近地址,并以您想要的方式使
注意:这两个都需要互联网许可。第一种方法还要求您拥有maps api密钥,但这是这两种方法中最简单的解决方案,但两者都应该相对容易。使用下面的代码获取当前位置坐标和城市名称
或者,你甚至可以通过查看示例来获得一些帮助 如果你还有麻烦,请告诉我
private class myLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location location) {
if(location!=null){
locManager.removeUpdates(locListener);
String longitude = "Longitude: " +location.getLongitude();
String latitude = "Latitude: " +location.getLatitude();
String altitiude = "Altitiude: " + location.getAltitude();
String cityName;
Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
public List<Address> addresses= gcd.getFromLocation (double latitude1, double longitude1, int maxResults)
List<Address> addresses;
try {
addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.size() > 0)
System.out.println(addresses.get(0).getLocality());
cityName=addresses.get(0).getLocality();
} catch (IOException e) {
e.printStackTrace();
}
showLocation.setText("City Name: "+cityName+"+ "\n"+longitude + "\n" + latitude + "\n" + altitiude);
progress.setVisibility(View.GONE);
}
}
public void getMap(String location) {
map_location = "geo:0,0?q=" + location;
Uri geoUri = Uri.parse(map_location);
Intent mapCall = new Intent(Intent.ACTION_VIEW, geoUri);
}