当前位置: 首页>>代码示例>>Java>>正文


Java Geocoder.getFromLocation方法代码示例

本文整理汇总了Java中android.location.Geocoder.getFromLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Geocoder.getFromLocation方法的具体用法?Java Geocoder.getFromLocation怎么用?Java Geocoder.getFromLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.location.Geocoder的用法示例。


在下文中一共展示了Geocoder.getFromLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAddress

import android.location.Geocoder; //导入方法依赖的package包/类
public String getAddress(Context context, double lat, double lng) {
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
    try {
        List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
        Address obj = addresses.get(0);

        String add = obj.getAddressLine(0);
        add = add + "," + obj.getAdminArea();
        add = add + "," + obj.getCountryName();

        return add;
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        return null;
    }
}
 
开发者ID:LewisVo,项目名称:Overkill,代码行数:18,代码来源:MapsActivity2.java

示例2: getGeocoderAddress

import android.location.Geocoder; //导入方法依赖的package包/类
public List<Address> getGeocoderAddress(Context context)
{
    if (location != null)
    {
        Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
        try
        {
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            return addresses;
        }
        catch (IOException e)
        {
            //e.printStackTrace();
            Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e);
        }
    }

    return null;
}
 
开发者ID:SkylineLabs,项目名称:FindX,代码行数:20,代码来源:SelectHome.java

示例3: setRegistrationLocation

import android.location.Geocoder; //导入方法依赖的package包/类
public void setRegistrationLocation(Intent data) {

    final Place place = PlacePicker.getPlace(getActivity(), data);
    Geocoder geocoder = new Geocoder(getActivity());

    try {
      List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
      elephant.registrationLoc.cityName = addresses.get(0).getAddressLine(0);
      if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
        elephant.registrationLoc.districtName = addresses.get(0).getSubAdminArea();
      }
      elephant.registrationLoc.provinceName = addresses.get(0).getAdminArea();
    } catch (IOException e) {
      e.printStackTrace();
    }

    registrationLocation.setText(elephant.registrationLoc.format());
  }
 
开发者ID:goutfeb,项目名称:ElephantAsia,代码行数:19,代码来源:EditRegistrationFragment.java

示例4: getLocalityNameEng

import android.location.Geocoder; //导入方法依赖的package包/类
public static String getLocalityNameEng(Context context, LatLng latLng) {
    Geocoder gcd = new Geocoder(context, Locale.US);
    try {
        List<Address> addresses = gcd.getFromLocation(latLng.latitude, latLng.longitude, 1);
        if (addresses.size() > 0) {
            Address address = addresses.get(0);
            String name = address.getCountryName();
            if (address.getLocality() != null)
                name = address.getLocality();
            return name;
        }
    } catch (IOException ex) {
        Log.d(TAG, Log.getStackTraceString(ex));
    }
    return null;
}
 
开发者ID:sept-en,项目名称:FlightSight-client,代码行数:17,代码来源:Utils.java

示例5: setBirthLocation

import android.location.Geocoder; //导入方法依赖的package包/类
/**
 * Set birth location from map
 *
 * @param location the location returned from the map picker
 */
public void setBirthLocation(Intent data) {
  final Place place = PlacePicker.getPlace(getActivity(), data);
  Geocoder geocoder = new Geocoder(getActivity());

  try {
    List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
    elephant.birthLoc.cityName = addresses.get(0).getAddressLine(0);
    if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
      elephant.birthLoc.districtName = addresses.get(0).getSubAdminArea();
    }
    elephant.birthLoc.provinceName = addresses.get(0).getAdminArea();
  } catch (IOException e) {
    e.printStackTrace();
  }

  birthLocation.setText(elephant.birthLoc.format());
}
 
开发者ID:goutfeb,项目名称:ElephantAsia,代码行数:23,代码来源:EditProfilFragment.java

示例6: getAddressFromLocation

import android.location.Geocoder; //导入方法依赖的package包/类
public Address getAddressFromLocation(final double latitude, final double longitude,
                                      final Context context) {

    Geocoder geocoder = new Geocoder(context, Locale.getDefault());

    try {
        List<Address> addressList = geocoder.getFromLocation(
                latitude, longitude, 1);
        if (addressList != null && addressList.size() > 0) {
            address = addressList.get(0);

        }
    } catch (IOException e) {
        Log.e(TAG, "Unable connect to Geocoder", e);
    }
    return address;


}
 
开发者ID:aliumujib,项目名称:Nibo,代码行数:20,代码来源:LocationAddress.java

示例7: updateMemoryPosition

import android.location.Geocoder; //导入方法依赖的package包/类
private void updateMemoryPosition(Memory memory, LatLng latLng) {
    Geocoder geocoder = new Geocoder(this);
    List<Address> matches = null;
    try {
        matches = geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1);
    } catch (IOException e) {
        e.printStackTrace();
    }

    Address bestMatch = (matches.isEmpty()) ? null : matches.get(0);
    int maxLine = bestMatch.getMaxAddressLineIndex();
    memory.city = bestMatch.getAddressLine(maxLine - 1);
    memory.country = bestMatch.getAddressLine(maxLine);
    memory.latitude = latLng.latitude;
    memory.longitude = latLng.longitude;
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:17,代码来源:MapsActivity.java

示例8: getGeocoderAddress

import android.location.Geocoder; //导入方法依赖的package包/类
/**
 * Get list of address by latitude and longitude
 * @return null or List<Address>
 */
public List<Address> getGeocoderAddress(Context context)
{
    if (location != null)
    {
        Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
        try 
        {
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            return addresses;
        } 
        catch (IOException e) 
        {
            //e.printStackTrace();
            Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e);
        }
    }

    return null;
}
 
开发者ID:SkylineLabs,项目名称:FindX,代码行数:24,代码来源:GPSTracker.java

示例9: getLocationName

import android.location.Geocoder; //导入方法依赖的package包/类
@ProtoMethod(description = "Get the location name of a given latitude and longitude", example = "")
@ProtoMethodParam(params = {"latitude", "longitude"})
public String getLocationName(double lat, double lon) {
    String gpsLocation = "";
    Geocoder gcd = new Geocoder(getContext(), Locale.getDefault());
    List<Address> addresses;
    try {
        addresses = gcd.getFromLocation(lat, lon, 1);
        gpsLocation = addresses.get(0).getLocality();

    } catch (IOException e) {
        e.printStackTrace();
    }

    return gpsLocation;
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:17,代码来源:PLocation.java

示例10: getCompleteAddressString

import android.location.Geocoder; //导入方法依赖的package包/类
@SuppressLint("LongLogTag")
private String getCompleteAddressString(double LATITUDE, double LONGITUDE) {
    String strAdd = "";
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
    try {
        List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
        if (addresses != null) {
            Address returnedAddress = addresses.get(0);

            StringBuilder strReturnedAddress = new StringBuilder("");

            for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
                strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
            }
            strAdd = strReturnedAddress.toString();
            Log.w("My Current loction address", "" + strReturnedAddress.toString());
        } else {
            Log.w("My Current loction address", "No Address returned!");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.w("My Current loction address", "Canont get Address!");
    }
    return strAdd;
}
 
开发者ID:fekracomputers,项目名称:MuslimMateAndroid,代码行数:26,代码来源:SelectLocationTabsActivity.java

示例11: getLocalityName

import android.location.Geocoder; //导入方法依赖的package包/类
@Nullable
public static String getLocalityName(Context context, LatLng latLng) {
    Geocoder gcd = new Geocoder(context, Locale.getDefault());
    try {
        List<Address> addresses = gcd.getFromLocation(latLng.latitude, latLng.longitude, 1);
        if (addresses.size() > 0) {
            Address address = addresses.get(0);
            String name = address.getCountryName();
            if (address.getLocality() != null)
                name = address.getLocality() + ", " + name;
            return name;
        }
    } catch (IOException ex) {
        Log.d(TAG, Log.getStackTraceString(ex));
    }
    return null;
}
 
开发者ID:sept-en,项目名称:FlightSight-client,代码行数:18,代码来源:Utils.java

示例12: getAddress

import android.location.Geocoder; //导入方法依赖的package包/类
/**
 * get address info
 */
private Address getAddress(double latitude, double longitude) {
  if(WXEnvironment.isApkDebugable()) {
    WXLogUtils.d(TAG, "into--[getAddress] latitude:" + latitude + " longitude:" + longitude);
  }
  try {
    if (mWXSDKInstance == null || mWXSDKInstance.isDestroy()) {
      return null;
    }
    Geocoder gc = new Geocoder(mWXSDKInstance.getContext());
    List<Address> list = gc.getFromLocation(latitude, longitude, 1);
    if (list != null && list.size() > 0) {
      return list.get(0);
    }
  } catch (Exception e) {
    WXLogUtils.e(TAG, e);
  }
  return null;
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:22,代码来源:DefaultLocation.java

示例13: setCurrentLocation

import android.location.Geocoder; //导入方法依赖的package包/类
/**
 * Set current location from map
 * TODO: Faire mieux la difference entre une location exacte et une
 *
 * @param location the location returned from the map picker
 */
public void setCurrentLocation(Intent data) {
  final Place place = PlacePicker.getPlace(getActivity(), data);
  Geocoder geocoder = new Geocoder(getActivity());

  try {
    List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
    elephant.currentLoc.cityName = addresses.get(0).getAddressLine(0);
    if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
      elephant.currentLoc.districtName = addresses.get(0).getSubAdminArea();
    }
    elephant.currentLoc.provinceName = addresses.get(0).getAdminArea();
  } catch (IOException e) {
    e.printStackTrace();
  }

  currentLocation.setText(elephant.currentLoc.format());
}
 
开发者ID:goutfeb,项目名称:ElephantAsia,代码行数:24,代码来源:AddProfilFragment.java

示例14: getAddress

import android.location.Geocoder; //导入方法依赖的package包/类
/**
 * Get address string from a geo point
 *
 * @return the address as a string.
 */
// see code attribution
public static String getAddress(Context context, double latitude, double longitude) {
    String pointAddress;
    try {
        Geocoder geocoder = new Geocoder(context);
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
        StringBuilder sb = new StringBuilder();
        if(addresses.size() > 0) {
            Address address = addresses.get(0);
            int n = address.getMaxAddressLineIndex();
            for(int i = 0; i <= n; i++) {
                if(i != 0) {
                    sb.append("\n");
                }
                sb.append(address.getAddressLine(i));
            }
            pointAddress = new String(sb);
        } else {
            pointAddress = "";
        }
    } catch (Exception e) {
        pointAddress = "";
    }
    return pointAddress;
}
 
开发者ID:CMPUT301F16T01,项目名称:Carrier,代码行数:31,代码来源:RequestController.java

示例15: getGeocoderAddress

import android.location.Geocoder; //导入方法依赖的package包/类
/**
 * Get list of address by latitude and longitude
 * @return null or List<Address>
 */
public List<Address> getGeocoderAddress(Context context) {
    if (location != null) {

        Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);

        try {
            /**
             * Geocoder.getFromLocation - Returns an array of Addresses
             * that are known to describe the area immediately surrounding the given latitude and longitude.
             */
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, this.geocoderMaxResults);

            return addresses;
        } catch (IOException e) {
            //e.printStackTrace();
            L.m("Impossible to connect to Geocoder");
        }
    }

    return null;
}
 
开发者ID:PGMacDesign,项目名称:PGMacTips,代码行数:26,代码来源:GPSTracker.java


注:本文中的android.location.Geocoder.getFromLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。