Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将Lat Long转换为谷歌地图ApiV2地址_Android_Google Maps Android Api 2 - Fatal编程技术网

Android 将Lat Long转换为谷歌地图ApiV2地址

Android 将Lat Long转换为谷歌地图ApiV2地址,android,google-maps-android-api-2,Android,Google Maps Android Api 2,我正在用谷歌地图Api V2制作一个演示应用程序 我添加了一个简单的标记,并使其可拖动 这是我的密码: onCreate方法() 集合信息方法() 添加标记法 现在,我希望在用户单击标记时显示地址 一个简单的问题是:如何从API v2中的Lat Long获取地址(名称)?您应该使用Android API中可用的。您需要调用getFromLocation(纬度、经度、maxResults),它将返回一个列表 public List<Address> getAddress() {

我正在用谷歌地图Api V2制作一个演示应用程序

我添加了一个简单的标记,并使其可拖动

这是我的密码:

onCreate方法()

集合信息方法()

添加标记法

现在,我希望在用户单击标记时显示地址

一个简单的问题是:如何从API v2中的Lat Long获取地址(名称)?

您应该使用
Android API中可用的。您需要调用
getFromLocation(纬度、经度、maxResults)
,它将返回一个
列表

public List<Address> getAddress() {
    if (latitude != 0 && longitude != 0) {
        try {
            Geocoder geocoder = new Geocoder(context);
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            String address = addresses.get(0).getAddressLine(0);
            String city = addresses.get(0).getAddressLine(1);
            String country = addresses.get(0).getAddressLine(2);
            Log.d("TAG", "address = " + address + ", city = " + city + ", country = " + country);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Toast.makeText(context, "latitude and longitude are null", Toast.LENGTH_LONG).show();
    }
    return addresses;
}
public List getAddress(){
如果(纬度!=0和经度!=0){
试一试{
Geocoder Geocoder=新的地理编码器(上下文);
列表地址=geocoder.getFromLocation(纬度,经度,1);
字符串地址=地址.get(0).getAddressLine(0);
字符串city=addresses.get(0).getAddressLine(1);
字符串country=addresses.get(0).getAddressLine(2);
日志d(“标签”、“地址=“+address+”、城市=“+city+”、国家=“+country”);
}捕获(例外e){
e、 printStackTrace();
}
}否则{
Toast.makeText(上下文,“纬度和经度为空”,Toast.LENGTH_LONG.show();
}
返回地址;
}

Hi Ovidiu。你能帮我解决这个问题吗?我希望当我把标记拖到边界上时,地图会自动滚动到另一个方向。可能吗谷歌地图api v2?也许你应该为此发布另一个问题。对不起,我不明白你到底想要什么?你能简单地解释一下吗,或者给出一个例子。我想当用户开始拖动标记并到达地图屏幕的边界(可见部分)时,地图屏幕应该自动滑动到另一侧,以便能够显示更多。试试这个,希望这对你有帮助。地理编码器总是给我超时异常,现在该怎么办?使用这个
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

  @Override
  public View getInfoWindow(Marker arg0) {

   return null;
  }

  @Override
  public View getInfoContents(Marker marker) {

   LayoutInflater inflater = (LayoutInflater) MapsDemo.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   View v = inflater.inflate(R.layout.custom_info, null);

   TextView tv = (TextView) v.findViewById(R.id.textView1);
   tv.setText(marker.getSnippet());

   return v;
  }
 });

 googleMap.setMyLocationEnabled(true);
 googleMap.getUiSettings().setRotateGesturesEnabled(true);
 googleMap.getUiSettings().setTiltGesturesEnabled(true);


 marker = googleMap.addMarker(new MarkerOptions()
  .position(ROMA)
  .title("Hello")
  .snippet("Nice Place")
  .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
  .draggable(true));

 @Override
 public void onMarkerDrag(Marker marker) {
  // TODO Auto-generated method stub
 }

 @Override
 public void onMarkerDragEnd(Marker marker) {
  LatLng field = marker.getPosition();
  System.out.println("LatitudenLongitude:" + field.latitude + " " + field.longitude);

 }

 @Override
 public void onMarkerDragStart(Marker marker) {
  // TODO Auto-generated method stub

 }

 @Override
 public void onMapLongClick(LatLng latlng) {
  // TODO Auto-generated method stub

 }

 @Override
 public void onMapClick(LatLng latlng) {
  // TODO Auto-generated method stub
 }
}
public List<Address> getAddress() {
    if (latitude != 0 && longitude != 0) {
        try {
            Geocoder geocoder = new Geocoder(context);
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            String address = addresses.get(0).getAddressLine(0);
            String city = addresses.get(0).getAddressLine(1);
            String country = addresses.get(0).getAddressLine(2);
            Log.d("TAG", "address = " + address + ", city = " + city + ", country = " + country);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Toast.makeText(context, "latitude and longitude are null", Toast.LENGTH_LONG).show();
    }
    return addresses;
}