JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java ME、Google Android 平台與 JavaCard 討論區 » Android  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 google map和語音搜尋
kovey3548





發文: 1
積分: 0
於 2014-10-23 23:47 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
想請問這段程式的問題出在哪裡?
可以安裝在模擬器和手機 但是執行後就跳出停止

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package map.research;
 
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.ArrayList;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.app.AlertDialog;
import android.app.Dialog;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.speech.RecognizerIntent;
import android.widget.Toast;
 
public class MainActivity extends MapActivity {
  
  private MapView _mapView = null;
  private MapController _mapController = null;
  private Geocoder _geo;
  private List<Address> _addresses = null;
    
  EditText _imf = null;
  Button _searchBtn = null;
  Button _voiceBtn = null;
  
  private static final int VOICE_RECOGNITION_REQUEST_CODE = 4321;
  
  @SuppressWarnings("null")
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    _mapView = (MapView)findViewById(R.id.mapview);    
      _mapView.setBuiltInZoomControls(true);      
      _mapController = _mapView.getController();      
      _geo = new Geocoder(this, Locale.CHINA);      
      _imf = (EditText)findViewById(R.id.imformation);      
      _searchBtn = (Button)findViewById(R.id.searchBtn);
      _voiceBtn = (Button)findViewById(R.id.voiceBtn);      
      _searchBtn.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v)
        {
          search(_imf.getText().toString());
        
        }});
      _voiceBtn.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v)
        {
          try
          {
            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
            intent.putExtra(RecognizerIntent.EXTRA_PROMPT,"Speech recognition demo");
            startActivityForResult(intent,VOICE_RECOGNITION_REQUEST_CODE);
          }
          catch(ActivityNotFoundException e)
          {
            Toast toast = Toast.makeText(getApplication(),"找不到語音設備!",Toast.LENGTH_SHORT);
            toast.show();
          }
        }});
  }
  
  @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
    if(requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK)
    {
      ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
      _imf.setText(results.get(0));
      search(_imf.getText().toString());
      super.onActivityResult(requestCode, resultCode, data);
    }
  }
  
  @Override
  protected Dialog onCreateDialog(int id)
  {
    return new AlertDialog.Builder(this).setTitle("查詢出錯哦").setMessage("路名/地名出錯,請重新輸入!").create();
  }
  
  @Override
  protected boolean isRouteDisplayed()
  {
    return false;
  }
  
  public void search(String path)
  {
    try
    {
      _addresses = _geo.getFromLocationName(path, 1);
    }
    catch (IOException e)
    {
      e.printStackTrace();
    };
    
    if(_addresses.size() == 0)
    {
      showDialog(1);
      GeoPoint geoBeijing = new GeoPoint((int) (39.906033 * 1E6),(int) (116.397700 * 1E6));
      _mapController = _mapView.getController();
      _mapController.setCenter(geoBeijing);
      _mapController.setZoom(4);
    }
    else
    {
      Address address = _addresses.get(0);
      GeoPoint geoPoint = new GeoPoint((int)(address.getLatitude() * 1E6),(int)(address.getLongitude() * 1E6));
      _mapController = _mapView.getController();
      _mapController.setCenter(geoPoint);
      _mapController.setZoom(17);
    }
  }
}
 


reply to postreply to post
» JWorld@TW »  Java ME、Google Android 平台與 JavaCard 討論區 » Android

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8