gxcm_amap_search 0.0.2 copy "gxcm_amap_search: ^0.0.2" to clipboard
gxcm_amap_search: ^0.0.2 copied to clipboard

高德官方没有提供search相关的Flutter插件,本插件针对高德地图搜索功能官方原生插件进行封装

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:gxcm_amap_search/SearchResultItem.dart';
import 'package:gxcm_amap_search/gxcm_amap_search.dart';


void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  final textEditingController = TextEditingController();
  List<SearchResultItem> dataList = [];

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


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            TextButton.icon(
                onPressed: () {
                  GxcmAmapSearch.setApiKey('f53141bcada3bd03fd79c37f652cd45f', 'df6898859be82405b9b41d8d1f1e86d3');
                  GxcmAmapSearch.updatePrivacyAgree(true);
                  GxcmAmapSearch.updatePrivacyShow(true, true);
                },
                icon: const Icon(Icons.login),
                label: const Text('注册id')),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Row(
                children: [
                  Expanded(
                    child: TextField(
                      controller: textEditingController,
                    ),
                  ),
                  TextButton.icon(
                      onPressed: () async {
                        dataList = await GxcmAmapSearch.searchKeyword(
                          keyword: textEditingController.text,
                          city: "深圳市",
                          types: "餐饮服务|商务住宅|生活服务|风景名胜|购物服务|科教文化服务|公司企业|政府机构及社会团体|道路附属设施|地名地址信息|公共设施",
                        );
                        setState(() {});
                      },
                      icon: const Icon(Icons.search),
                      label: const Text('关键词搜索')),
                ],
              ),
            ),
            TextButton.icon(
                onPressed: () async {
                  dataList = await GxcmAmapSearch.searchAround(
                      latitude: 22.600323788793503, longitude: 114.10581646859714,
                      types: "餐饮服务|商务住宅|生活服务|风景名胜|购物服务|科教文化服务|公司企业|政府机构及社会团体|道路附属设施|地名地址信息|公共设施",
                      keyword: textEditingController.text);
                  setState(() {});
                },
                icon: const Icon(Icons.search),
                label: const Text('周边搜索')),
            Expanded(
              child: ListView.builder(
                itemBuilder: (context, index) {
                  return  ListTile(
                    title: Text(dataList[index].title),
                    subtitle: Text(dataList[index].snippet),
                    trailing: Text(dataList[index].cityName),
                  );
                },
                itemCount: dataList.length,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
125
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

高德官方没有提供search相关的Flutter插件,本插件针对高德地图搜索功能官方原生插件进行封装

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on gxcm_amap_search