2015-12-19 74 views

回答

0

您可以使用以下方法:

// get latlng from address 
    public LatLng getLocationFromAddress(String strAddress) { 

     Geocoder coder = new Geocoder(context, Locale.getDefault()); 
     List<Address> address; 
     LatLng p1 = null; 

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

      p1 = new LatLng(location.getLatitude(), location.getLongitude()); 

      return p1; 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return p1; 
    }