Google지도 api (거리 매트릭스 및지도 API)를 통해 geolocation을 사용하여지도에서 거리를 계산하고 핀을 표시하는 앱이 있습니다. 내 논리에 성능 문제가 있습니다. (데이터베이스에 100 개의 주소가 있으며, 모두 가져오고, 거리 매트릭스에 모두 들어가서 내 위치에 대한 거리를 얻습니다.) 사용자가 클릭 할 때마다이 작업을 수행하고 있습니다. 위치 업데이트 버튼. 하지만 그 방법에 관한 이야기가 있습니다. 새로 고침 버튼을 클릭 할 때마다 100 개의 요청을하고 있는데, 이는 단지 1 명의 사용자를위한 것입니다. 분명히 API가 하루에 요청을 제한하는 경우가 있습니다. 내 질문입니다 : 어떻게하면 더 나은 성능을 얻을 수 있으며,이 응용 프로그램이 더 빨리 실행되고 일일 요청 한도에 도달하지 못하는 내 논리를 향상시킬 수 있습니까? 이 앱을 사용하는 약 1000 명의 사람들이 있습니다.Google지도 API 요청 성능 문제
<?php
header('Content-Type: application/json');
// Open the connection with the database
$conn = mysql_connect('localhost', 'gennovacap', 'coupons');
mysql_select_db('coupons', $conn);
$id_voucher = $_POST['id_voucher'];
$uuid = $_POST['uuid'];
// $uuid = "1343C38F-C0F3-4D86-B763-C14CFBF1DAC3";
// $id_voucher = 8;
$q = mysql_query("SELECT * FROM vouchers WHERE id_voucher = ".$id_voucher);
$voucher = mysql_fetch_assoc($q);
if(preg_match('/[\+]{2}+/', $voucher['address'])) {
$i = 0;
foreach(explode('++', $voucher['address']) as $address){
$address = preg_replace('/\s/m', '+', $address);
$request = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$address."&sensor=true";
$result = simplexml_load_file($request);
$latitude = $result->result->geometry->location[0]->lat;
$longitude = $result->result->geometry->location[0]->lng;
$json['markers'][$i]['latitude'] = $latitude;
$json['markers'][$i]['longitude'] = $longitude;
$json['markers'][$i]['titlev'] = $voucher['name'];
$i++;
}
} else {
$address = preg_replace('/\s/m', '+', $voucher['address']);
$request = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$address."&sensor=true";
$result = simplexml_load_file($request);
$latitude = $result->result->geometry->location[0]->lat;
$longitude = $result->result->geometry->location[0]->lng;
$json['markers'][0]['latitude'] = $latitude[0];
$json['markers'][0]['longitude'] = $longitude[0];
$json['markers'][0]['titlev'] = $voucher['name'];
}
// See if the user redeemed this coupon
$redemption = mysql_query("SELECT * FROM redemptions WHERE uuid = '".$uuid."' AND id_voucher = '".$id_voucher."'");
$count = mysql_num_rows($redemption);
if($count > 0) {
$created_at = mysql_fetch_row($redemption);
$json['titlev'] = $voucher['name'];
$json['deal'] = $voucher['deal'];
$json['redemptions'] = false;
$json['redemptions_text'] = $created_at[3];
} else {
$json['titlev'] = $voucher['name'];
$json['deal'] = $voucher['deal'];
$json['redemptions'] = true;
$json['redemptions_text'] = "Redeem This Coupon";
}
print json_encode($json);