在main中新建
然后导入html文件
其中代码如下:
<!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代码:
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中的代码:
<?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>
这样就能实现地图下钻的功能了
标签:总结,info,function,30,地图,intent,mySubway,btn,id From: https://www.cnblogs.com/nanbei666/p/17274689.html