3/30每日总结:地图下钻功能的实现
所花时间:3小时
代码量:如下:
博客量:本学期截至目前31篇
了解到的知识点:地图下钻
在main中新建
然后导入html文件
其中代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | <!DOCTYPE html> <html> <head> <meta charset= "UTF-8" > <!--重要meta, 必须!--> <meta name= "viewport" content= "width=320, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,shrink-to-fit=no" /> <title>SUBWAY</title> </head> <body> <div id= "mybox" ></div> <script src= "https://webapi.amap.com/subway?v=1.0&key=b09132fa0d59581435755699c411c397&callback=cbk" ></script> <script type= "text/javascript" > window.cbk = function() { var mySubway = subway( "mybox" , { adcode: 1100 , theme: "colorful" , client: 0 , doubleclick: { switch : true } }); //地铁加载完成,执行complete事件 mySubway.event.on( "subway.complete" , function(ev, info) { var id = info.id; }); //点击站点,显示此站点的信息窗体 mySubway.event.on( "station.touch" , function(ev, info) { var id = info.id; mySubway.stopAnimation(); mySubway.addInfoWindow(id, {}); var center = mySubway.getStCenter(id); mySubway.setCenter(center); }); //点击线路名,高亮此线路 mySubway.event.on( "lineName.touch" , function(ev, info) { mySubway.showLine(info.id); var select_obj = qs( '#g-select' ); mySubway.setFitView(select_obj); var center = mySubway.getSelectedLineCenter(); mySubway.setCenter(center); }); //点击空白, 关闭infowindow mySubway.event.on( "subway.touch" , function() { mySubway.clearInfoWindow(); }); //设置起点 mySubway.event.on( "startStation.touch" , function(ev, info) { mySubway.stopAnimation(); mySubway.clearInfoWindow(); mySubway.setSt art(info.id, {}); startInfo = info; route(); }); //设置终点 mySubway.event.on( "endStation.touch" , function(ev, info) { mySubway.stopAnimation(); mySubway.clearInfoWindow(); mySubway.setEnd(info.id, {}); endInfo = info; route(); }); //路线规划 var startInfo = {}, endInfo = {}; function route() { if (startInfo.id && endInfo.id) { mySubway.route(startInfo.id, endInfo.id, {}); startInfo = {}; endInfo = {}; } } }; </script> </body> |
这个key的值可能不一样可能需要改。
MainActivity代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | package com.example.chaxun; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import com.example.chaxun.Dao.Dao; public class MainActivity extends AppCompatActivity implements View.OnClickListener { Dao Dao = new Dao(); private Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.btn_selectbyline).setOnClickListener( this ); findViewById(R.id.btn_selectbystation).setOnClickListener( this ); findViewById(R.id.btn_selectbetween).setOnClickListener( this ); findViewById(R.id.btn_ditu).setOnClickListener( this ); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.btn_selectbyline: intent = new Intent(MainActivity. this , SearchLineActivity. class ); startActivity(intent); break ; case R.id.btn_selectbystation: intent = new Intent(MainActivity. this , SearchStationActivity. class ); startActivity(intent); break ; case R.id.btn_selectbetween: intent = new Intent(MainActivity. this , ChangeStationActivity. class ); startActivity(intent); break ; case R.id.btn_ditu: intent = new Intent(MainActivity. this , MapActivity. class ); startActivity(intent); break ; } } } |
xml中的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?xml version= "1.0" encoding= "utf-8" ?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:app= "http://schemas.android.com/apk/res-auto" xmlns:tools= "http://schemas.android.com/tools" android:layout_width= "match_parent" android:layout_height= "match_parent" tools:context= ".MapActivity" > <!-- <TextView--> <!-- android:layout_width= "wrap_content" --> <!-- android:layout_height= "wrap_content" --> <!-- android:text= "Hello World!" --> <!-- app:layout_constraintBottom_toBottomOf= "parent" --> <!-- app:layout_constraintLeft_toLeftOf= "parent" --> <!-- app:layout_constraintRight_toRightOf= "parent" --> <!-- app:layout_constraintTop_toTopOf= "parent" />--> <WebView android:layout_width= "match_parent" android:layout_height= "match_parent" android:id= "@+id/mWebView" > </WebView> </androidx.constraintlayout.widget.ConstraintLayout> |
这样就能实现地图下钻的功能了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了