读完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点击打开链接