Places (C++)OverviewThe Places API allows users to discover places/points of interest and view details about them such as address and contact information; some places may even have rich content such as images and reviews. The Places API also facilitates management of places and categories, allowing users to save and remove them. Place DefinitionA place is a point of interest, it could be a favorite restaurant, a park or someone's home. A QPlace object represents a place by acting as a container for various information about that place. This information can be divided into 2 broad classifications
The place details consist of properties of the place, such as the name, location, contact information and so on. When a place is returned during a search, these details are filled in. Sometimes in order to save bandwidth, there are further details about the place that can be retrieved on an individual place by place basis, if the user is interested. The QPlace::detailsFetched() function can be queried to see if all available details have been fetched, and if not, QPlaceManager::getPlaceDetails() can be used to retrieve them. Precisely which details are populated during a search and which need to be fetched individually may vary from provider to provider. (See Information about plugins). The rich content of a place consists of items such as images, reviews and editorials. Potentially there may be many rich content items, so they are treated separately from the place details. They can be retrieved in a paged fashion via QPlaceManager::getPlaceContent(). If necessary, the content may be assigned to a place so it can act as a convenient container. Common OperationsInitializing a ManagerAll places functionality is facilitated by a QPlaceManager instance. One must specify a QGeoServiceProvider in order to create the QPlaceManager Discovery/SearchIn order to perform a search operation we simply create a QPlaceSearchRequest and set the desired search parameters, such as a search term and search center. The request is an asynchronous operation so we need a slot to handle the completion of the request. In the handler we check that there are no errors and that our search result type is a place. If so we can then retrieve some of the core details of the place. At the end of the slot, we delete the reply since they are for single use only. Note: Depending upon the plugin backend that was chosen, the search results may contain places which have further details that can be fetched on a place by place basis. To fetch these other details see Fetching Place Details. PagingIf the plugin supports paging, limit and offset parameters may be provided to the search request. CorrectionsSuggested search term corrections to user input may also be returned with the search results if desired. A maximum number can be set in the search request. ... ... ... Fetching Place DetailsA place that has been returned from a search request may have more details that can be fetched. The following demonstrates how to check if there are further details and if so how to request them. ... ... Fetching Rich ContentRich content such as images and reviews is retrieved through the manager and then if required assigned to a place. We can handle the content request as shown below. It is important to note that the results in the QPlaceContentReply, is a QPlaceContent::Collection which is essentially a QMap<int, QPlaceContent>. The key int in this case is the index of the content, and the value is the content itself. Due to the way Content is implemented it is possible to convert a content type as follows QPlaceImage image = content; //provided that 'content' has a type QPlace::ImageType The usage of the QPlaceContent::Collection and the conversion between content and its subtypes means that code for handling the mechanics of paging reviews, images and editorials can be easily shared. Search SuggestionsThe retrieval of search term suggestions is very similar to performing a place search. A QPlaceSearchRequest is used just like a place search, the only difference being that the search term is set to a partially completed string. And when the request is done, we can use the reply to show the suggestions. RecommendationsRecommendations are suggestions for places that are similar to a specified place. The retrieval of recommendations is very similar to retrieving search term suggestions or performing a place search. ... ... Saving a PlaceThe saving of a new place is performed as follows, we create a QPlace instance and populate it with information such as a name, address and coordinate. Once done we can invoke QPlaceManager::savePlace() to begin a save operation. ... Once a place is saved the reply contains the new identifier for that place. Note that to save an already existing place, the QPlace::placeId() must be filled in with the correct identifier. Otherwise a new place will be created if empty or the wrong place overwritten if the identifier is incorrect. When a place is saved, the QPlaceManager may emit QPlaceManager::placedAdded() or QPlaceManager::placeUpdated() signals. However whether a manager does so or not is provider specific, managers accessing places from a web service will typically not emit these signals while managers accessing places locally stored generally will. CaveatsThe Places API is currently designed for only saving core details. Saving rich content like images and reviews or details like supplier and rating is not a supported use case. Typically a manager will generally ignore these fields upon save and may produce a warning message if they are populated. The Places API only supports saving of the following core details:
It is possible that providers may only support a subset of these. See the provider plugins for more details. Saving of properties such as the rating, extended attributes, images, reviews, editorials and supplier is explicitly not supported by the Places API. Saving Between ManagersWhen saving places between managers, there are a few things to be aware of. Some fields of a place such as the id, categories and icons are manager specific entities for example the categories in one manager may not be recognized in another. Therefore trying to save a place directly from one manager to another is not possible. The typical approach is to use the QPlaceManager::compatiblePlace() function, it creates a copy of a place, but only copies data that the manager supports. Manager specific data such as the place identifier is not copied over. The new copy is now suitable for saving into the manager. If the manager supports matching by alternative identifiers, an alternative identifier attribute is assigned to the copy (see Matching places between managers) Removing a PlaceThe removal of a place is performed as follows: ... ... When a place is removed, the QPlaceManager may emit the QPlaceManager::placeRemoved() signal. Whether a manager does so is provider specific. Managers accessing places from a web service will typically not emit these signals, while managers accessing places stored locally generally will. Using CategoriesCategories are keywords that can describe a place. For example, 'park', 'theater', 'restaurant'. A place could be described by many categories, it could be a park and a music venue and a ferry or bus stop. To use categories they must first be initialized. ... ... After the categories have been initialized we can then use these category functions.
To retrieve the top level categories we use the QPlaceManager::childCategories() function but do not provide a category identifier. If we did provide an identifier then we could retrieve a category's children. Saving a CategoryThe following shows how to save a category ... ... When a category is saved, the QPlaceManager may emit QPlaceManager::categoryAdded() or QPlaceManager::categoryUpdated() signals. However whether a manager does so or not is provider specific, managers accessing places from a web service will typically not emit these signals while managers accessing places locally stored generally will. Removing a CategoryCategory removal is very similar to removing a place ... ... When a category is removed, the QPlaceManager may emit the QPlaceManager::categoryRemoved() signal. Whether a manager does so is provider specific. Managers accessing places from a web service will typically not emit these signals, while managers accessing places stored locally generally will. Matching Places Between ManagersSometimes you may want to cross reference whether places from one manager match those from another manager. Such a situation may arise where one manager provides read-only access to places (origin manager) while another second r/w manager (destination manager) is used to save selected favorites from the first. During a search of the origin manager we may want to know which ones have been 'favorited' into the destination manager and perhaps display a customized favorite name rather than the original name. The matching mechanism can vary between managers, but is typically accomplished through an alternative identifier. As part of the save process, the place identifier from the origin manager is saved as an alternative identifier attribute in the destination manager (which can have its own place identifier scheme). In the following example, the origin manager is from the 'nokia' QGeoServiceProider, therefore as part of the saving process an alternative identifier attribute, x_id_nokia, is set for the place saved into the destination manager (when QPlaceManager::compatiblePlace() is called) origin R/O manager(nokia) destination R/W manager (nokia_places_jsondb) Save Place id: ae246 ---> Place id: 0001 Attribute type: x_provider Attribute type: x_id_nokia Attribute value: nokia Attribute text value: ae246 In order to perform the matching, we create a QPlaceMatchRequest and assign it the search results from the origin manager. The QPlaceMatchRequest will be used on the destination manager to return corresponding places. We also specify matching parameters which are key value pairs. As mentioned previously, this can vary depending on the manager but typically the key is QPlaceMatchRequest::AlternativeId to indicate we are matching by alternative id, the value in this case would be x_id_nokia which specifies which alternative identifier attribute we are using to do the matching. ... ... Classes in PlacesData Classes
Request Classes
|