#include <stdio.h>
#include <stdlib.h>
+#include <math.h>
#include "mapzen_plugin.h"
#include "mapzen_plugin_internal.h"
#include "mapzen_api.hpp"
#define DEFAULT_NUM_RESULTS 10
#define _PROVIDER_KEY_MAX_SIZE 1024
+#define R_EARTH 6378137.0
static const double LATITUDE_RANGE = 85.05113;
static const double LONGITUDE_RANGE = 180.0;
if (searchKeyword)
place_req->search_string = g_strdup_printf("%s", searchKeyword);
- if (!searchKeyword && !categoryId) {
- g_free(calldata_place);
- calldata_place = NULL;
- g_free(place_req->maps_key);
- place_req->maps_key = NULL;
- g_free(place_req);
- place_req = NULL;
- return MAPS_ERROR_INVALID_PARAMETER;
- }
-
if (searchKeyword) {
g_free(searchKeyword);
searchKeyword = NULL;
place_req->boundary->circle.center.longitude = bound->circle.center.longitude;
place_req->boundary->circle.radius = bound->circle.radius;
} else if (bound->type == MAPS_AREA_RECTANGLE) {
- place_req->boundary->type = MAPZEN_BOUNDARY_RECT;
- place_req->boundary->rect.top_left.latitude = bound->rect.top_left.latitude;
- place_req->boundary->rect.top_left.longitude = bound->rect.top_left.longitude;
- place_req->boundary->rect.bottom_right.latitude = bound->rect.bottom_right.latitude;
- place_req->boundary->rect.bottom_right.longitude = bound->rect.bottom_right.longitude;
+ place_req->boundary->type = MAPZEN_BOUNDARY_CIRCLE;
+ gdouble centerLat = (bound->rect.top_left.latitude + bound->rect.bottom_right.latitude) * 0.5;
+ gdouble centerLon = (bound->rect.top_left.longitude + bound->rect.bottom_right.longitude) * 0.5;
+ //aprox radius calculation (Equirectangular approximation) - works great for small distances
+ gdouble dLat = degrees_to_radians(bound->rect.top_left.latitude - bound->rect.bottom_right.latitude);
+ gdouble dLon = degrees_to_radians(bound->rect.top_left.longitude - bound->rect.bottom_right.longitude);
+ gdouble mLat = degrees_to_radians(bound->rect.top_left.latitude + bound->rect.bottom_right.latitude) * 0.5;
+ gdouble radius = R_EARTH * 0.5 * sqrt( pow((dLon * cos(mLat)), 2.0) + pow(dLat, 2.0) );
+ place_req->boundary->circle.center.latitude = centerLat;
+ place_req->boundary->circle.center.longitude = centerLon;
+ place_req->boundary->circle.radius = radius;
}
}
}