【问题标题】:Android Intent for Navigation - how can I ensure it will navigate me to the right place?Android Intent for Navigation - 我如何确保它将导航到正确的位置?
【发布时间】:2015-06-24 15:17:52
【问题描述】:

我正在开发一个应用程序,该应用程序允许用户保存目的地,然后一键导航到该目的地。在多种情况下,输入的位置(由 Google Place API 自动完成提供)然后单击以进行导航,会将我带到错误的位置。

一个例子是寻找乔治布什洲际机场。当我开始输入时,自动完成建议是:

乔治布什洲际机场,北航站楼路,休斯顿,美国

但是,当我启动导航到该位置的意图时:

new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + mapData.getPlace());

其中 mapData.getPlace() 是与上述地址相同的字符串,导航启动并将我引导至 William P. Hobby 机场。

这是另一个例子。当我搜索爱好机场时,地方自动完成提示:

霍比机场,机场大道,休斯顿,美国

但是,当我启动导航意图时(如上所述),它会将我导航到

休斯顿霍比机场希尔顿逸林酒店

AutoComplete 提供的地址似乎不是可导航地址,导航意图选择最接近的建议。

我尝试过的一种方法是过滤自动完成结果,例如 AutoCompleteFilter(见此处https://developers.google.com/places/android/autocomplete)。我的代码如下:

    List<Integer> filterTypes = new ArrayList<Integer>();
    filterTypes.add(Place.TYPE_STREET_ADDRESS);
    AutocompleteFilter filter = AutocompleteFilter.create(filterTypes);

    // Create and attach adapter
    mAdapter = new PlaceAutocompleteAdapter(context, android.R.layout.simple_list_item_1,
            mGoogleApiClient,MainActivity.CURRENT_BOUNDS , filter);

但这经常导致“获取自动完成预测 API 调用时出错:Status{statusCode=NETWORK_ERROR, resolution=null}”

【问题讨论】:

    标签: android android-intent navigation google-places-api


    【解决方案1】:

    我通过对自动完成的结果进行地理编码解决了这个问题。我使用 Geocoder 对象并采用它提供的第一个建议。

        Geocoder geocoder = new Geocoder(context, Locale.US);
        try {
            // Take first suggestion from geocoder object
            List<Address> coordinates = geocoder.getFromLocationName(mapData.getPlace(),1);
    
            //If a geocode result is supplied, use it. Otherwise, use the string from mapData
            if (coordinates.size() > 0){
                double latitude = coordinates.get(coordinates.size() - 1).getLatitude();
                double longitude = coordinates.get(coordinates.size() - 1).getLongitude();
                coords = (latitude + "," + longitude);}
    
            else{
                coords = mapData.getPlace();}
    

    然后我将坐标传递给导航意图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-19
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多