Android studio 在颤振多段线点的官方文档中给出的示例中,这些API_键和MAP_API_键是什么
以下是颤振文档中给出的颤振多段线点的示例Android studio 在颤振多段线点的官方文档中给出的示例中,这些API_键和MAP_API_键是什么,android-studio,flutter,google-polyline,Android Studio,Flutter,Google Polyline,以下是颤振文档中给出的颤振多段线点的示例 import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:flutter_polyline_points/flutter_polyline_points.dart'; import 'Constants.dart'; void main() => runApp(MyA
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'Constants.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Polyline example',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.orange,
),
home: MapScreen(),
);
}
}
class MapScreen extends StatefulWidget {
@override
_MapScreenState createState() => _MapScreenState();
}
class _MapScreenState extends State<MapScreen> {
GoogleMapController mapController;
double _originLatitude = 6.5212402, _originLongitude = 3.3679965;
double _destLatitude = 6.849660, _destLongitude = 3.648190;
Map<MarkerId, Marker> markers = {};
Map<PolylineId, Polyline> polylines = {};
List<LatLng> polylineCoordinates = [];
PolylinePoints polylinePoints = PolylinePoints();
String googleAPiKey = Constants.MAP_API_KEY;
@override
void initState() {
super.initState();
/// origin marker
_addMarker(LatLng(_originLatitude, _originLongitude), "origin",
BitmapDescriptor.defaultMarker);
/// destination marker
_addMarker(LatLng(_destLatitude, _destLongitude), "destination",
BitmapDescriptor.defaultMarkerWithHue(90));
_getPolyline();
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(_originLatitude, _originLongitude), zoom: 15),
myLocationEnabled: true,
tiltGesturesEnabled: true,
compassEnabled: true,
scrollGesturesEnabled: true,
zoomGesturesEnabled: true,
onMapCreated: _onMapCreated,
markers: Set<Marker>.of(markers.values),
polylines: Set<Polyline>.of(polylines.values),
)),
);
}
void _onMapCreated(GoogleMapController controller) async {
mapController = controller;
}
_addMarker(LatLng position, String id, BitmapDescriptor descriptor) {
MarkerId markerId = MarkerId(id);
Marker marker =
Marker(markerId: markerId, icon: descriptor, position: position);
markers[markerId] = marker;
}
_addPolyLine() {
PolylineId id = PolylineId("poly");
Polyline polyline = Polyline(
polylineId: id, color: Colors.red, points: polylineCoordinates);
polylines[id] = polyline;
setState(() {});
}
_getPolyline() async {
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
Constants.API_KEY,
PointLatLng(_originLatitude, _originLongitude),
PointLatLng(_destLatitude, _destLongitude),
travelMode: TravelMode.driving,
wayPoints: [PolylineWayPoint(location: "Sabo, Yaba Lagos Nigeria")]
);
if (result.points.isNotEmpty) {
result.points.forEach((PointLatLng point) {
polylineCoordinates.add(LatLng(point.latitude, point.longitude));
});
}
_addPolyLine();
}
}
导入“包装:颤振/材料.省道”;
导入“包:google_-maps_-flatter/google_-maps_-flatter.dart”;
导入“包:颤振多段线点/颤振多段线点.省道”;
导入“Constants.dart”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“多段线示例”,
主题:主题数据(
//这是应用程序的主题。
//
//尝试使用“flutter run”运行应用程序。您将看到
//应用程序有一个蓝色工具栏。然后,在不退出应用程序的情况下,重试
//将下面的primarySwatch更改为Colors.green,然后调用
//“热重新加载”(在运行“颤振运行”的控制台中按“r”,
//或者只需将更改保存到颤振IDE中的“热重新加载”。
//请注意,计数器没有重置回零;应用程序
//未重新启动。
原始样本:颜色。橙色,
),
主页:MapScreen(),
);
}
}
类MapScreen扩展StatefulWidget{
@凌驾
_MapScreenState createState()=>\u MapScreenState();
}
类_MapScreenState扩展状态{
谷歌地图控制器;
双原纬度=6.5212402,原经度=3.3679965;
双纬度=6.849660,双经度=3.648190;
地图标记={};
映射多段线={};
列出多段线坐标=[];
多段线点多段线点=多段线点();
字符串googleAPiKey=Constants.MAP\u API\u KEY;
@凌驾
void initState(){
super.initState();
///原点标记
_添加标记(LatLng(_原始纬度,_原始经度),“原点”,
BitmapDescriptor.defaultMarker);
///目的地标记
_添加标记(LatLng(_destLatitude,_destLatitude),“目的地”,
defaultMarkerWithHue(90));
_getPolyline();
}
@凌驾
小部件构建(构建上下文){
返回安全区(
孩子:脚手架(
正文:谷歌地图(
initialCameraPosition:CameraPosition(
目标:LatLng(原始纬度,原始经度),缩放:15),
myLocationEnabled:对,
倾斜姿势启用:正确,
同谋:是的,
scrollGesturesEnabled:正确,
zoomGesturesEnabled:对,
onMapCreated:_onMapCreated,
标记:一组(标记值),
多段线:一组(多段线值),
)),
);
}
void\u onMapCreated(谷歌地图控制器)异步{
mapController=控制器;
}
_addMarker(LatLng位置、字符串id、位图描述符){
MarkerId MarkerId=MarkerId(id);
标记器=
标记(markerId:markerId,图标:描述符,位置:position);
markers[markerId]=标记器;
}
_添加多段线(){
多段线id=多段线id(“多边形”);
多段线多段线=多段线(
多段线id:id,颜色:Colors.red,点:多段线坐标);
多段线[id]=多段线;
setState((){});
}
_getPolyline()异步{
PolylineResult结果=等待polylinePoints.GetRouteBeween坐标(
常量.API_键,
点定位(_原始纬度,_原始经度),
点定位(_dest纬度,_dest经度),
travelMode:travelMode.driving,
航路点:[多段线航路点(位置:尼日利亚亚巴-拉各斯萨博市”)]
);
if(result.points.isNotEmpty){
结果.points.forEach((PointLatLng点){
多段线坐标.add(LatLng(点.纬度,点.经度));
});
}
_添加多段线();
}
}
API_键和映射API_键之间有什么区别?我在尝试执行示例时遇到了错误
我的要求是在谷歌地图中获得两个地方之间的多段线点。
请给我举一些例子来画多段线;如果你有。我在画路线时遇到了问题。尝试了许多示例,但没有得到它。要使用谷歌地图,您需要从以下链接获得API密钥: 这应该是
MAP\u API\u键
常量
要使用direction api,您需要从以下链接获取api密钥:
这应该是
API\u键
常量。但是如果使用同一个键,两个键都是相同的NOI。你得到了什么?如果使用同一个键,什么都不会发生。关于如何在地图上绘制多段线点,你能给我提供一些链接吗?你是否已经从开发者控制台为你的项目启用了这两个API@sushreesomamohanty@adadion是的,我有