讀完http://blog.csdn.net/woshishuoshuoa/article/details/9793327中已經可以定位到任一個你想要定位的地方,不過會受到安卓版本的限制的,至少是安卓4.1及以上的版本,而本文給出的列子可以明顯標誌出該地址的經緯度,受版本的影響很小,一般的安卓機子都可以跑滴哦~~~由於小菜鳥尚未能全弄明白,所以這裡就想給出原始碼好了,喜歡安卓的親們可以給出親們的好主意哦!!!不過,小菜鳥以後會回來更新的哦~~~
xml部署檔案,在xml中簡單的放了一個編輯框和一個查詢按鈕,以及一個放地圖的fragment
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:hint="請輸入地址" android:id="@+id/edit_search" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="2" /> <Button android:id="@+id/btn_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" android:text="搜尋" /> </LinearLayout><fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment"/></LinearLayout>
建立了一個實體類MyAdress
public class MyAdress {
private String addressName;private Double lat;private Double lng;public String getAddressName() {return addressName;}public void setAddressName(String addressName) {this.addressName = addressName;}public Double getLat() {return lat;}public void setLat(Double lat) {this.lat = lat;}public Double getLng() {return lng;}public void setLng(Double lng) {this.lng = lng;}}
activity中的代碼如下:
}
結果圖:輸入上海後查詢等待圖:
查詢結果,有一個明顯的表彰標出上海,點擊一下標誌處便可以查看上海所在的經緯度哦
看完本文,有興趣的親們可以繼續看一看http://blog.csdn.net/woshishuoshuoa/article/details/9812693點擊開啟連結