pushpin for San Fransisco shape placed in sea

Surya 6 Reputation points
2021-10-08T11:01:42.78+00:00

var cities = ["San Francisco", "Dallas", "Houston", "Los Angeles", "New York", "Philadelphia", "San Antonio"];

In Bing Maps, Am trying to place the marker for the above locations. But the San Fransisco location's pushpin placed in sea.

Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(cities, geoDataRequestOptions, map,  
        (data) => {  
            var value = data.location;  
            if (data.results.length > 0 && data.results[0].Polygons !== null) {  
                var polygons = data.results[0].Polygons;  
                var dataBounds = Microsoft.Maps.LocationRect.fromShapes(data.results[0].Polygons);  
                var loc = new Microsoft.Maps.Location(dataBounds.center.latitude, dataBounds.center.longitude);  
                var pin = new Microsoft.Maps.Pushpin(loc, {  
                        icon: svgIcon,  
                        anchor: new Microsoft.Maps.Point(20 / 2, 20 / 2)  
                });  
                map.entities.push(pin);  
                locs.push(pin);  
                map.setView({ bounds: Microsoft.Maps.LocationRect.fromLocations(locs), padding: 80 });    
            }  
        });  

I expect the marker to be placed on the center of the San Fransico. Please let us know if there is any dynamic way to achieve this.

138809-sanfransico.png

TIA

Bing | Bing Search APIs | Bing Web Search API
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
840 questions
Windows for home | Windows 11 | Apps
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. IoTGirl 3,696 Reputation points Microsoft Employee Moderator
    2021-10-13T21:53:16.767+00:00

    Hello,

    The point is returned from your calculation of center of the polygon and changing it to a rectangle then calculating a point. To get a better answer I have two options for you.

    1. Call the Geocoder API for "San Francisco" https://learn.microsoft.com/en-us/bingmaps/rest-services/locations
    2. Call proper polygon math to get the actual center of the polygon like https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/getcentroid

    Sincerely,
    IoTGirl

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.