示例#1
0
QGeoSearchReply* QGeoSearchManagerEngineNokia::geocode(const QGeoAddress &address,
        QGeoBoundingArea *bounds)
{
    if (!supportsGeocoding()) {
        QGeoSearchReply *reply = new QGeoSearchReply(QGeoSearchReply::UnsupportedOptionError, "Geocoding is not supported by this service provider.", this);
        emit error(reply, reply->error(), reply->errorString());
        return reply;
    }

    QString requestString = "http://";
    requestString += m_host;
    requestString += "/geocoder/gc/2.0?referer=" + m_referer;

    if (!m_token.isNull())
        requestString += "&token=" + m_token;

    if (!m_applicationId.isEmpty()) {
        requestString += "&app_id=";
        requestString += m_applicationId;
    }

    requestString += "&lg=";
    requestString += languageToMarc(locale().language());

    requestString += "&country=";
    requestString += address.country();

    if (!address.state().isEmpty()) {
        requestString += "&state=";
        requestString += address.state();
    }

    if (!address.city().isEmpty()) {
        requestString += "&city=";
        requestString += address.city();
    }

    if (!address.postcode().isEmpty()) {
        requestString += "&zip=";
        requestString += address.postcode();
    }

    if (!address.street().isEmpty()) {
        requestString += "&street=";
        requestString += address.street();
    }    

    // TODO?
    // street number has been removed from QGeoAddress
    // do we need to try to split it out from QGeoAddress::street
    // in order to geocode properly

    // Old code:
//    if (!address.streetNumber().isEmpty()) {
//        requestString += "&number=";
//        requestString += address.streetNumber();
//    }

    return search(requestString, bounds);
}
QGeoSearchReply* QGeoSearchManagerEngineCm::geocode(const QGeoAddress &address,
        QGeoBoundingArea *bounds)
{
    if (!supportsGeocoding()) {
        QGeoSearchReply *reply = new QGeoSearchReply(QGeoSearchReply::UnsupportedOptionError, "Geocoding is not supported by this service provider.", this);
        emit error(reply, reply->error(), reply->errorString());
        return reply;
    }
    QString searchString;

    if(!address.street().isEmpty()) {
        searchString += address.street();
        searchString += ",";
    }
    if(!address.city().isEmpty()) {
        searchString += address.city();
        searchString += ",";
    }
    if(!address.postcode().isEmpty()) {
        searchString += address.postcode();
        searchString += ",";
    }
    if(!address.district().isEmpty()) {
        searchString += address.district();
        searchString += ",";
    }
    if(!address.county().isEmpty()) {
        searchString += address.county();
        searchString += ",";
    }
    if(!address.state().isEmpty()) {
        searchString += address.state();
        searchString += ",";
    }
    if(!address.country().isEmpty()) {
        searchString += address.country();
        searchString += ",";
    }
    if(!address.countryCode().isEmpty()) {
        searchString += address.countryCode();
        searchString += ",";
    }

	// Note:  this code is not called?
	DBG_CM(SEARCH_M, INFO_L, "Warning - geocode() method is called\n");


    QString cmSearchUrl = "http://" + m_host + "/" + m_token +"/geocoding/v2/find.js?query=";
    cmSearchUrl += searchString;

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

    return search(cmSearchUrl, QGeoSearchManager::SearchGeocode, -1, 0,bounds);
}