finished map markers

This commit is contained in:
Win 2024-09-23 19:37:32 +07:00
parent ffa0c0ff34
commit c7a1f130cf
1 changed files with 12 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:latlong2/latlong.dart';
void main() async {
@ -34,6 +34,13 @@ class _MapScreenState extends State<MapScreen> {
await rootBundle.loadString("assets/data/stations.json");
final data = await json.decode(stationFile);
setState(() {
_stations = data["records"];
_getMarkers();
});
}
Future<void> _getMarkers() async {
List<Marker> markers = [];
for (var i = 0; i < _stations.length; i++) {
@ -43,13 +50,13 @@ class _MapScreenState extends State<MapScreen> {
width: 30,
point: LatLng(double.tryParse(_stations[i][4].toString()) ?? 0,
double.tryParse(_stations[i][5].toString()) ?? 0),
builder: (ctx) => const Icon(Icons.pin_drop),
builder: (ctx) =>
const Icon(Icons.pin_drop, color: Colors.brown, size: 50.0),
),
);
}
setState(() {
_stations = data["records"];
_markers = markers;
});
}
@ -73,11 +80,11 @@ class _MapScreenState extends State<MapScreen> {
onPressed: () => {print("deez")}, child: const Icon(Icons.add)),
body: FlutterMap(
options:
MapOptions(center: const LatLng(13.736717, 100.523186), zoom: 2.0),
MapOptions(center: const LatLng(13.736717, 100.523186), zoom: 10.0),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'net.winscloud,net',
//userAgentPackageName: 'net.winscloud.srt',
),
MarkerLayer(markers: _markers)
],