在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;
}
答案 0 :(得分:0)
当您有longitude
和latitude
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=" + latitude + "," + longitude));
startActivity(intent);
获取区域位置:例如:NewYork City ...
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
}
答案 1 :(得分: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;