dencity_map_plugin

Creator: coderz1093

Last updated:

0 purchases

dencity_map_plugin Image
dencity_map_plugin Images

Languages

Categories

Add to Cart

Description:

dencity map plugin

dencity_map_plugin #
An Android Native Plugin Support for Dencitylite Android Applications


👋 Get started #
This is a plugin for Dencitylite Android Applications. This plugin is used to show the map in the Dencitylite Android Applications.
Prerequisites #
Add the following dependencies in your project level android/app/src/main/res/strings.xml file.
<string name="google_maps_key">GOOGLE_MAPS_API_KEY</string>
copied to clipboard
package com.dencity.dencity_map_plugin_example

import com.dencity.dencity_map_plugin.NativeViewFactory
import com.dencity.dencity_map_plugin.SearchScreenViewFactory
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel


class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)

flutterEngine
.platformViewsController
.registry
.registerViewFactory(
"com.dencity.dencity_map_plugin/map_view",
NativeViewFactory(this)
)
flutterEngine
.platformViewsController
.registry
.registerViewFactory(
"com.dencity.dencity_map_plugin/search_screen_view",
SearchScreenViewFactory(this)
)
val CHANNEL = "com.dencity.dencity_map_plugin/search_screen_distance"
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
if (call.method == "getDistance") {
val distance = call.argument<String>("key")
if (distance != null) {
// Use the distance value here
println("Received distance: $distance")
result.success(null)
} else {
result.error("UNAVAILABLE", "Distance not available", null)
}
} else {
result.notImplemented()
}
}
}
}

copied to clipboard
🚀 Installation #
Add dependency #
Add the plugin to your pubspec.yaml file
dependencies:
dencity_map_plugin: <latest_version>
copied to clipboard
The latest version is:
The latest version including pre-releases is:
Usage #
Main Screen View with all the markers within 500m radius #
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: PlatformViewLink(
viewType: 'com.dencity.dencity_map_plugin/map_view',
surfaceFactory: (context, controller) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
gestureRecognizers: const <Factory<
OneSequenceGestureRecognizer>>{},
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
);
},
onCreatePlatformView: (params) {
return PlatformViewsService.initSurfaceAndroidView(
id: params.id,
viewType: 'com.dencity.dencity_map_plugin/map_view',
layoutDirection: TextDirection.ltr,
creationParams: const <String, dynamic>{},
creationParamsCodec: const StandardMessageCodec(),
onFocus: () {
params.onFocusChanged(true);
},
)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..create();
},
),
),
);
}
copied to clipboard
Search Screen View with multiple polylines and also the markers within 500m radius and a platform channel for distance calculation #

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:permission_handler/permission_handler.dart';

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

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

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

class _MyAppState extends State<MyApp> {

String distanceCallResponse = "Not Avaiable";
static const distanceCallChannel = const MethodChannel(
'com.dencity.dencity_map_plugin/search_screen_distance');

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

Future<void> requestLocationPermission() async {
PermissionStatus status = await Permission.location.request();

if (status.isGranted) {
// The location permission is granted. You can now access the user's location.
} else if (status.isDenied) {
// The location permission is denied. You can't access the user's location.
} else if (status.isPermanentlyDenied) {
// The location permission is permanently denied. The user needs to enable it in the settings.
}
}

Future<void> getPlatformVersion() async {
try {
distanceCallChannel.setMethodCallHandler((call) async {
switch (call.method) {
case 'getDistance':
setState(() {
distanceCallResponse = call.arguments['key'];
});
print('Distance call received ${call.arguments['key']}');
return Future.value('Distance call received');
default:
throw MissingPluginException();
}
});
} on PlatformException {
setState(() {
distanceCallResponse = 'Failed to get distance.';
});
}
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(distanceCallResponse),
),
body: PlatformViewLink(
viewType: 'com.dencity.dencity_map_plugin/map_view',
surfaceFactory: (context, controller) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
gestureRecognizers: const <Factory<
OneSequenceGestureRecognizer>>{},
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
);
},
onCreatePlatformView: (params) {
return PlatformViewsService.initSurfaceAndroidView(
id: params.id,
viewType: 'com.dencity.dencity_map_plugin/search_screen_view',
layoutDirection: TextDirection.ltr,
creationParams: const <String, dynamic>{
"origin": "48.8566, 2.3522",
"destination": "48.8606, 2.3376",
"apiKey": "GOOGLE_MAPS_API_KEY",
"parkingLotsURL":
"API_FOR_PARKING_LOTS",
},
creationParamsCodec: const StandardMessageCodec(),
onFocus: () {
params.onFocusChanged(true);
},
)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..create();
},
),
),
);
}
}

copied to clipboard
🔑 Generate App key #

Go to the Google Maps Platform > Credentials page.
On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key.
Click Close.The new API key is listed on the Credentials page under API keys.(Remember to restrict the API key before using it in production.)

👨‍💻 Developer Details #

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.