欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Android调用百度地图Web端接口,实现百度定位、导航

[+]
 

 

[java] view plain copy
 
  1. <h1><span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">  
  2. </span></h1><h1><span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">  
  3. </span></h1><h1><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span style="font-size:24px;">一、概述</span></span></h1>  
第一次写博客,希望各位朋友勿喷!因为之前做过什么百度定位和高德地图导航这些,都是嵌入它们的SDK,代码量
 
很复杂,过程也有点繁琐,所以今天才发表这篇文章。
 
提前说明,工程是在手机客户端调用百度地图的Web端接口,而不是直接在自己的项目显示,到时候不要看错怪我哟
 
尴尬,写这篇文章也是因为个人觉得自己做得还不够百度自带写的好,能力太差没办法哭
 
另外IOS端(或者其他)的可上官网查看:http://developer.baidu.com/map/wiki/index.php?title=uri/api/android

二、效果图

三、代码

代码很简单,三句搞定一切。不用导入包,不用加权限。如果想改变地址,只需要把位置传给Url中的address
 

 

[java] view plain copy
 
  1. public class MainActivity extends AppCompatActivity {  
  2.     private TextView addressText;  
  3.     private Button navigationButton;  
  4.     @Override  
  5.     protected void onCreate(Bundle savedInstanceState) {  
  6.         super.onCreate(savedInstanceState);  
  7.         setContentView(R.layout.activity_main);  
  8.   
  9.         addressText = (TextView) findViewById(R.id.id_address);  
  10.         navigationButton = (Button) findViewById(R.id.id_navigation);  
  11.   
  12.         navigationButton.setOnClickListener(new View.OnClickListener() {  
  13.             @Override  
  14.             public void onClick(View view) {  
  15.                 String address = "address=" + addressText.getText().toString();  
  16.                 /**调用百度地图Web页面 
  17.                  * address=LocaltionAddress&src=YourAppName 
  18.                  */  
  19.                 String uristr = "http://api.map.baidu.com/geocoder?" + address  
  20.                         + "&output=html&src=yhc";  
  21.                 Uri uri = Uri.parse(uristr);  
  22.                 Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
  23.                 startActivity(intent);  
  24.             }  
  25.         });  
  26.     }  
  27. }  
布局就两个控件,一个TextView和Button,不用贴代码了吧,我比较懒,所以界面就那个样子偷笑最后我不知道为什么头部插入代码的时候会出现一大块空格,而且还删不掉。知道的朋友记得留言教教小白。


来自  
http://blog.csdn.net/fjekin/article/details/51003603

普通分类: