简体   繁体   English

Android:快速搜寻地图结果

[英]Android: quick search to map results

Does anyone know how to activate a map from a quick search box? 有谁知道如何通过快速搜索框激活地图?

My app displays the users location and some places pulled from my website. 我的应用程序显示用户的位置以及从我的网站提取的一些位置。 I have added a quick search box, following instruction from Google Android docs but I can't get it to initiate the map. 我已按照Google Android文档的说明添加了一个快速搜索框,但无法启动地图。 I can get it to print the query, so I know its getting the data, but when I try to sumbit the query to a class, or set the content view it crashes! 我可以获取它来打印查询,因此我知道它获取了数据,但是当我尝试将查询汇总到一个类或设置内容视图时,它崩溃了! (I have commented out the lines that cause a crash). (我已注释掉导致崩溃的行)。

public class SearchActivity extends MapActivity {  
    public boolean touched = false; 
    private MapView mapView;
    Main mc = new Main();

    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        //setContentView(R.layout.main);
        //mapView = (MapView) findViewById(R.id.mapView);
        //mapView.getController();
        handleIntent(getIntent());
    }  

    private void handleIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            // handles a search query
            String query = intent.getStringExtra(SearchManager.QUERY);
            //mc.activateMapFromQuery(query);
        }
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
} 

here is what I can read in the LogCat which I believe may be relevant: 这是我在LogCat中可以阅读的内容,我认为这可能是相关的:

Starting Activity: Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.maps.android.example/com.maps.android.example.Main paused=false}
onSignalStrengthChanged
onSignalStrengthChanged
grantUriPermission URI=file:///data/local/tmp/Example.apk
No content provider found for:
Force stopping package com.maps.android.example uid=10115
WIN DEATH: Window{40834690 com.maps.android.example/com.maps.android.example.Main paused=false}

I found the solution! 我找到了解决方案!

In the CatLog above it says onSignalStrengthChanged after the Starting Activity. 在上面的CatLog中,启动活动后显示onSignalStrengthChanged。 This made me realise that GPS was still updating the user location when it was trying to perform the search and display the new map. 这使我意识到,GPS在尝试执行搜索并显示新地图时仍在更新用户位置。 So I simply turned off the GPS activity on the initiation of the intent. 因此,我只是在启动意图时关闭了GPS活动。

This actually sped up the app, and now the search works! 这实际上加快了应用程序的速度,现在搜索有效!

Thanks to everyone who looked at this and tried to help. 感谢所有查看此内容并尝试提供帮助的人。 Hope this is of some assistance to others :) 希望这对其他人有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM