Tencent Map WeChat Send Location Function

The following was reproduced from the batter article "Mimicking the WeChat Send Location Function"

Author: Battery

Links: https://www.jianshu.com/p/47b3ada2e36d

Source: Short Book

Copyright belongs to the author. For commercial reprinting, please contact the author for authorization. For non-commercial reprinting, please indicate the source.


WeChat's Send Location feature is a very convenient feature that locates the user's current location, then requests the POI around the user, and can also be dragged to get other locations to send to the other party. This Demo combines Tencent Map SDK to achieve similar functions.

Use scenarios

Drag the map to select the center point of the map, and then request store information around the point. You can specify the type of search store by setting a search category, such as food, schools, and so on.

Get ready

Core Code:

1. Set the pin, fix it in the center of the map, and listen for the pin to follow as the map moves:

- (void)mapViewRegionChange:(QMapView *)mapView {
    // Update Location
    _annotation.coordinate = mapView.centerCoordinate;

2. Configure the peripheral retrieval function and set the retrieval type to "Food":

- (void)searchCurrentLocationWithKeyword:(NSString *)keyword {
CLLocationCoordinate2D centerCoord = self.mapView.centerCoordinate;

    QMSPoiSearchOption *option = [[QMSPoiSearchOption alloc] init];
    if (keyword.length > 0) {
        option.keyword = keyword;
    option.boundary = [NSString stringWithFormat:@"nearby(%f,%f,2000,1)", centerCoord.latitude, centerCoord.longitude];
    [option setFilter:@"category=Delicious food"];
    [self.mapSearcher searchWithPoiSearchOption:option];

3. Parse and retrieve the results, move the map horizon, and display the results on the tableView:

- (void)searchWithPoiSearchOption:(QMSPoiSearchOption *)poiSearchOption didReceiveResult:(QMSPoiSearchResult *)poiSearchResult {
    NSLog(@"%@", poiSearchResult);

    if (poiSearchResult.count == 0) {

    // Move the map to the first place in search results
    if (_searchBar.text.length > 0) {
        _selectedIndex = 0;
        QMSPoiData *firstData = poiSearchResult.dataArray[0];
        _annotation.coordinate = firstData.location;
        [self.mapView setCenterCoordinate:firstData.location animated:YES];
    } else {
        _selectedIndex = -1;

    _searchResultArray = poiSearchResult.dataArray;
    [_searchResultTableView reloadData];

That's the core code. A TableView to show addresses and a SearchBar to search for locations have been added to Demo. Interested students can enter the code cloud at the bottom of the article to download a complete example.

Example: Search for food near the Xierqi Metro

Interested students can Code cloud Download Demo to try it.

Tags: gitee poi lbs cde

Posted by noj75 on Tue, 24 May 2022 20:53:47 +0300