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 Web Search
Bing Web Search
A Bing service that gives you enhanced search details from billions of web documents.
127 questions
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
585 questions
Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
245 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. IoTGirl 2,976 Reputation points Microsoft Employee
    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