1
0
Эх сурвалжийг харах

Add custom region support to import venues script

Alan Lam 7 жил өмнө
parent
commit
d1bcbc0cb2

+ 3 - 3
engine/geolocation.php

@@ -65,11 +65,11 @@ class Geolocation {
 		}
 	}
 
-	public static function geocode($address) {
+	public static function geocode($address, $region = "uk") {
 		$query = [
 			"address" =>  $address,
 			"key" => GOOGLE_API_KEY,
-			"region" => "uk",
+			"region" => $region,
 		];
 
 		$url = "https://maps.googleapis.com/maps/api/geocode/json?" . http_build_query($query);
@@ -84,4 +84,4 @@ class Geolocation {
 
 		return $results;
 	}
-}
+}

+ 3 - 1
tasks/import_venues.php

@@ -9,6 +9,8 @@ $customer_id = readline("Type customer ID: ");
 $customer = Customer::get($customer_id);
 if(!$customer) die("Customer not found.");
 
+$region = readline("Type region code: ");
+
 $confirm = readline($customer->name . ": Confirm Y/N: ");
 if($confirm != "Y") die("Aborted");
 
@@ -145,7 +147,7 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
 			}
 
 			try {
-				$results = Geolocation::geocode($query);
+				$results = Geolocation::geocode($query, $region);
 				if($results) {
 					$result = $results[0];
 					$location->latitude = $result->geometry->location->lat;