rc_bd_map 0.0.2 rc_bd_map: ^0.0.2 copied to clipboard
集成百度地图的定位以及地图展示,支持ios、android
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:rc_bd_map/rc_bd_map.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await RcBdMap.platformVersion;
// bool initMap = await RcBdMap.initMap("3GS6uOGZItAIAi3FkRVSRraHBdTKwGui");
// platformVersion = initMap.toString();
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
print("地图初始化结果====》"+platformVersion.toString());
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
Future<void> getCurrentLocation() async {
try {
// platformVersion = await RcBdMap.platformVersion;
await RcBdMap.initMap("3GS6uOGZItAIAi3FkRVSRraHBdTKwGui");
// platformVersion = initMap.toString();
} on PlatformException {
print("=====================================+>");
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: <Widget>[
Container(
height: 200,
child: Center(
child: Text('Running on: $_platformVersion\n'),
),
),
GestureDetector(
onTap: (){
getCurrentLocation();
return;
},
child: Container(
height: 300,
child: RcBdMap.getMap(25.109031, 102.739138, "和谐世纪"),
// child: Center(child: Text("地图"),),
),
),
GestureDetector(
onTap: (){
RcBdMap.checkMapType(25.109031, 102.739138, "小学");
},
child: Container(
height: 100,
child: Center(
child: Text("小学"),
),
),
)
],
)
),
);
}
}