0

在 Google 地图中显示地址的位置。怎么可能..我如何在谷歌地图上获得地址..

显示覆盖区域的位置....帮帮我....我尝试了代码但不适合我....

Geocoder coder = new Geocoder(this);
List<Address> address;

try {
address = coder.getFromLocationName(strAddress,7);
if (address == null) {
    return null;
}
Address location = address.get(1);
location.getLatitude();
location.getLongitude();

 geo1 = new GeoPoint((int) (location.getLatitude() * 1E6),
                  (int) (location.getLongitude() * 1E6));

 return geo1;
  }
4

2 回答 2

0

代码显示在谷歌地图上的位置当你有longitudelatitude

        Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
        Uri.parse("geo:0,0?q=" + latitude + "," + longitude));
        startActivity(intent);

获取区域位置:例如:纽约市...

        try {
        Geocoder gCoder = new Geocoder(getApplicationContext());
        ArrayList<Address> addresses = (ArrayList<Address>) gCoder
                .getFromLocation(latitude, longitude, 1);
        if (addresses != null && addresses.size() > 0) {

            Log.d(addresses.get(0)
                    .getThoroughfare()
                    + " "
                    + addresses.get(0).getSubAdminArea()
                    + " "
                    + addresses.get(0).getAdminArea()
                    + ", "
                    + addresses.get(0).getCountryName());
        }
    } catch (Exception e) {
        // TODO: handle exception
    }
于 2013-04-09T11:59:31.737 回答
0

请使用此代码

  @override

 public boolean onTouchEvent(MotionEvent event, MapView mapView) {  

  if (event.getAction() == 1) {  
   GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(), (int) event.getY());

 Geocoder geoCoder = new Geocoder(getBaseContext(),  
  Locale.getDefault());  
 try {  
 List<Address> addresses = geoCoder.getFromLocation(  
  p.getLatitudeE6()/ 1E6, p.getLongitudeE6()/ 1E6,1);  

  String add = "";  
 if (addresses.size() > 0) {  
  for (int i = 0; i < addresses.get(0).getMaxAddressLineIndex(); i++)  
  add += addresses.get(0).getAddressLine(i) + "\n";  
 }  

 Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();  
 } catch (IOException e) {  
 e.printStackTrace();  
 }  
return true;  
于 2013-04-09T12:24:12.497 回答