【问题标题】:Get the location of all company's branches on a map在地图上获取公司所有分支机构的位置
【发布时间】:2017-02-11 16:58:46
【问题描述】:

我可以通过输入公司名称从地图中获取公司所有分支机构的位置,以便我可以在我的应用程序中使用它,即 如果我输入“Levi's”,它应该返回一个城市的分支机构位置。

【问题讨论】:

  • 你可以google这样的问题,这没有代码,你正在寻找意见......尝试重写它

标签: android api google-maps


【解决方案1】:

您可以向谷歌地点发送请求以获取该位置的纬度、经度,然后通过设置标记将其显示在地图上。 https://developers.google.com/places/android-api/

您应该使用的一小部分代码(上面的链接中有一个更好的示例)

Place place = PlaceAutocomplete.getPlace(this, data);
                    String addressString = place.getAddress().toString();
                    List<android.location.Address> addresses;
                    actionBar.setTitle(addressString);
                    Geocoder geocoder = new Geocoder(context);
                    try {
                        addresses = geocoder.getFromLocationName(addressString, 1);
                        if (!addresses.isEmpty()) {
                            MarkerOptions markerOptions = new MarkerOptions();
                            LatLng latLng = new LatLng(addresses.get(0).getLatitude(), addresses.get(0).getLongitude());
                            markerOptions.position(latLng);
                            markerOptions.title("Searched location");
                            mMap.clear();
                            markerLatLng = latLng;
                            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17));
                            mMap.addMarker(markerOptions);
                        }
                        }catch(IOException e){
                            Toast.makeText(context, "There was a problem finding your location", Toast.LENGTH_LONG).show();
                            e.printStackTrace();
                        }

我不确定你想做什么,但我认为自动完成选项可能最适合你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    • 2016-07-01
    • 2012-11-03
    • 2014-01-23
    • 2018-06-02
    • 2016-05-28
    • 2022-10-13
    相关资源
    最近更新 更多