Say*_*ari 9 android google-maps-api-2
我想在顶部添加一个"搜索栏",Google Maps v2如我在谷歌播放中剪下的这张小图片所示.

我该怎么做呢?谢谢
这将是一个迟来的答案,但应该对这个非常普遍的需求有一个答案。
在这里,我们基本上需要做的是用来Google Geocoder搜索用户在文本框中提到的地址。
我们可以这样做,
Geocoder geo = new Geocoder(getBaseContext());
List<Address> gotAddresses = null;
try {
gotAddresses = geocoder.getFromLocationName(locationName[0], 1);
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
此方法返回可用地址列表,在此代码中我们仅接受 1 个地址,如果需要,我们可以通过更改上述方法中最后一个参数的值来获取多个地址。然后,
Address address = (Address) gotAddresses.get(0);
LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
String properAddress = String.format("%s, %s",
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
address.getCountryName());
mMap.addMarker(new MarkerOptions()
.position(new LatLng(address.getLatitude(), address.getLongitude())).draggable(true)
.title(properAddress)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin)));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12569 次 |
| 最近记录: |