在谷歌地图中实现requestlocationchange

时间:2014-03-26 11:07:05

标签: android google-maps location

在我的应用程序中,我有谷歌地图,我目前正在使用gps显示我的位置,但我有一个用户输入字段,用户可以根据用户输入给出他们的位置,我的位置应该更改为用户位置< / p>

2 个答案:

答案 0 :(得分:1)

您可以使用CameraUpdate更改位置

LatLng latLng = user's position
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng(latLng)
map.moveCamera(cameraUpdate);

如果用户输入地址而不是坐标(非常可能),您可以使用地理编码器从地址中获取坐标

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

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

答案 1 :(得分:0)