android google maps之 简单定位(四)

读完http://blog.csdn.net/woshishuoshuoa/article/details/9793327中已经可以定位到任一个你想要定位的地方,不过会受到安卓版本的限制的,至少是安卓4.1及以上的版本,而本文给出的列子可以明显标志出该地址的经纬度,受版本的影响很小,一般的安卓机子都可以跑滴哦~~~由于小菜鸟尚未能全弄明白,所以这里就想给出源代码好了,喜欢安卓的亲们可以给出亲们的好主意哦!!!不过,小菜鸟以后会回来更新的哦~~~

xml部署文件,在xml中简单的放了一个编辑框和一个查询按钮,以及一个放地图的fragment

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.      android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.     <LinearLayout   
  7.         android:layout_width="fill_parent"  
  8.         android:layout_height="wrap_content"  
  9.        android:orientation="horizontal" >  
  10.  <EditText   
  11.     android:hint="请输入地址"  
  12.     android:id="@+id/edit_search"   
  13.     android:layout_width="match_parent"  
  14.     android:layout_height="wrap_content"  
  15.     android:layout_weight="2"  
  16.      />  
  17.       
  18. <Button   
  19.     android:id="@+id/btn_search"  
  20.     android:layout_width="wrap_content"  
  21.     android:layout_height="wrap_content"  
  22.     android:layout_weight="0"  
  23.     android:text="搜索"  
  24.     />  
  25.     </LinearLayout>  
  26. <fragment xmlns:android="http://schemas.android.com/apk/res/android"  
  27.           android:id="@+id/map"  
  28.           android:layout_width="match_parent"  
  29.           android:layout_height="match_parent"  
  30.            class="com.google.android.gms.maps.SupportMapFragment"/>  
  31. </LinearLayout>  
<?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 {

  1. private String addressName;  
  2. private Double lat;  
  3. private Double lng;  
  4. public String getAddressName() {  
  5.     return addressName;  
  6. }  
  7. public void setAddressName(String addressName) {  
  8.     this.addressName = addressName;  
  9. }  
  10. public Double getLat() {  
  11.     return lat;  
  12. }  
  13. public void setLat(Double lat) {  
  14.     this.lat = lat;  
  15. }  
  16. public Double getLng() {  
  17.     return lng;  
  18. }  
  19. public void setLng(Double lng) {  
  20.     this.lng = lng;  
  21. }  
	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点击打开链接

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值