Ejemplo n.º 1
0
QGeoSearchReply* QGeoSearchManagerEngineCm::search(const QString &searchString,
        QGeoSearchManager::SearchTypes searchTypes,
        int limit,
        int offset,
        QGeoBoundingArea *bounds)
{
	// Prepare request url for Geocoding:
	QString requestString = "http://" + m_host + "/" + m_token +"/geocoding/v2/find.js?query=" + searchString;


	if (limit > 0) {
		// Number of results to return 
		requestString += "&results=" + QString::number(limit);
	}
	if (offset > 0) {
		// Number of results to skip from beginning (allow paging of results)
		requestString += "&skip=" + QString::number(offset);
	}

	if ((bounds) && (bounds->isValid())) {
        QGeoBoundingBox* box = 0;
        QGeoBoundingCircle* circle = 0;
        switch (bounds->type()) {

			// Note:  Searching with Bounding area specified could be extremely slow for large areas
			//		  so use it only with high zoom level in frontend map application
            case QGeoBoundingArea::BoxType:
                box = static_cast<QGeoBoundingBox*>(bounds);
                if (box && box->isValid()) {
					DBG_CM(SEARCH_M, INFO_L, "Using search with bounding box specified");
					// "southern_latitude,western_longitude,northern_latitude,eastern_longitude"
					requestString += "&bbox=";
					requestString += QString::number(box->bottomLeft().latitude()) + "," ;	// southern_latitude
					requestString += QString::number(box->bottomLeft().longitude()) + "," ;	// western_longitude
					requestString += QString::number(box->topRight().latitude()) + "," ;	// northern_latitude
					requestString += QString::number(box->topRight().longitude());			// eastern_longitude
					requestString += "&bbox_only=false";
                }
                break;
            case QGeoBoundingArea::CircleType:
                circle = static_cast<QGeoBoundingCircle*>(bounds);
                if (circle && circle->isValid()) {
					DBG_CM(SEARCH_M, ERR_L, "Using search with circle area specified: Not implemented. Around area is ignored!");
                }
                break;
            default:
                break;
        }

	}

	// return location information like road, city, county, country, postcode in returned results:
    // requestString += "&return_location=true";

	return search(requestString, bounds, limit, offset);
}