Android:快速搜索到地图结果
有谁知道如何从快速搜索框激活地图?
我的应用程序显示用户位置以及从我的网站中提取的一些位置。我按照 Google Android 文档的说明添加了一个快速搜索框,但我无法让它启动地图。我可以让它打印查询,所以我知道它获取数据,但是当我尝试将查询提交给类或设置内容视图时,它崩溃了! (我已经注释掉了导致崩溃的行)。
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;
}
}
以下是我在 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}
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. 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:
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}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案!
在上面的 CatLog 中,它在启动 Activity 之后显示 onSignalStrengthChanged。这让我意识到 GPS 在尝试执行搜索并显示新地图时仍在更新用户位置。所以我只是在意图启动时关闭了 GPS 活动。
这实际上加快了应用程序的速度,现在搜索可以正常工作了!
感谢所有看到此内容并试图提供帮助的人。希望这对其他人有一些帮助:)
I found the solution!
In the CatLog above it says onSignalStrengthChanged after the Starting Activity. 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. So I simply turned off the GPS activity on the initiation of the intent.
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 :)