android google maps之 簡單定位(四)

來源:互聯網
上載者:User

讀完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點擊開啟連結

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.