Flutter在高德地图上显示定位

1.先申请一个apikeyhttps://lbs.amap.com/api/android-sdk/guide/create-project/get-key

2.在AndroidManifest.xml中增加你申请的key值,并增加对应的权限要显示的activity


    
    
    
    
    
    
    
    
    
    
        
        
        
        
        
    

3.修改pubspec.yaml,增加依赖:

dependencies:
    flutter_amap: ^0.0.1
    flutter_alipay: "^0.1.0"

4.在要用的地方导入:

import 'package:flutter_amap/flutter_amap.dart';

最后显示全部代码:

import 'package:flutter/material.dart';
import 'package:flutter_amap/flutter_amap.dart';

void main(){
  FlutterAmap.setApiKey("你的key");
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State {

  FlutterAmap amap = new FlutterAmap();

  @override
  initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        ),
        body: new Center(
            child: new InkWell(child: new Text("Show Map"),onTap: this.show)
        ),
      ),
    );
  }


  void show(){
    amap.show(
        mapview: new AMapView(
            centerCoordinate: new LatLng(39.9242, 116.3979),
            zoomLevel: 13.0,
            mapType: MapType.night,
            showsUserLocation: true
        ),
        title: new TitleOptions(title: "我的地图")
    );
    amap.onLocationUpdated.listen((Location location){
      print("Location changed $location") ;
    });
  }
}

 

你可能感兴趣的:(Flutter)