step 12 : ubah dari nomitism ke google apis untuk address
This commit is contained in:
@@ -12,6 +12,11 @@ class Constant {
|
||||
static String bearerName = "absensi-sas";
|
||||
static String accountGoogle = "absensi-google-account";
|
||||
|
||||
// api key google map
|
||||
static String apikeyGoogleMap = "AIzaSyCiN7EeJsUpXVLQKFfrj3sE5OTKebjpzek";
|
||||
static String baseUrlGoogleMapApis =
|
||||
"https://maps.googleapis.com/maps/api/geocode/json?";
|
||||
|
||||
static double designHeightPhone = 844;
|
||||
static double designWidthPhone = 390;
|
||||
|
||||
|
||||
41
lib/app/googleapis_location.dart
Normal file
41
lib/app/googleapis_location.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
Future<String> searchPosition(LatLng position) async {
|
||||
const apiKey = "AIzaSyAVUr4Ku4O1HlSkK8n9KGnUyqvsXBL-yfs";
|
||||
final latitudeString = position.latitude.toString();
|
||||
final longitudeString = position.longitude.toString();
|
||||
const url = 'https://maps.googleapis.com/maps/api/geocode/json';
|
||||
|
||||
try {
|
||||
final response = await Dio().get(
|
||||
url,
|
||||
queryParameters: {
|
||||
'latlng': '$latitudeString,$longitudeString',
|
||||
'key': apiKey,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
// Mengambil compound_code dari hasil JSON
|
||||
final plusCode = data['plus_code'];
|
||||
if (plusCode != null && plusCode['compound_code'] != null) {
|
||||
return plusCode['compound_code'];
|
||||
} else {
|
||||
print('Alamat Tidak Ditemukan');
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
print('Failed to load data');
|
||||
return "";
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error: $e');
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> positionToAddressGoogleApis(LatLng position) async {
|
||||
return await searchPosition(position);
|
||||
}
|
||||
Reference in New Issue
Block a user