bing-maps

Why BingMap heatMap doesn't show the correct location?


I was trying to show a location using heatMap module in bingMap. When I try to use some location heatMap show me diffrect location to that long and lat,

HeatMap

I just change the code like following way `

Microsoft.Maps.loadModule('Microsoft.Maps.HeatMap', function () {
    var mapDiv = map.getRootElement();
    
    var locations = [];
    
    locations.push(map.tryPixelToLocation(new Microsoft.Maps.Point(28.150900,-81.468440), Microsoft.Maps.PixelReference.control));
    
    
    var heatMap = new Microsoft.Maps.HeatMapLayer(locations);
    map.layers.insert(heatMap);
});

This location is for 410 Marlberry Leaf Ave, Kissimmee, FL 34758, USA but heatMap show me a location in ALESKA


Solution

  • The issue is that you are taking the lat/long coordinates and treating it as a pixel point and converting it into a location. This results in a completely different coordinate. Remove the call to map.tryPixelToLocation( and use the Location class instead of the Point class.

    Here is a modified version of your code:

    Microsoft.Maps.loadModule('Microsoft.Maps.HeatMap', function () {
        var mapDiv = map.getRootElement();
        
        var locations = [];
        
        locations.push(new Microsoft.Maps.Location(28.150900,-81.468440));
        
        
        var heatMap = new Microsoft.Maps.HeatMapLayer(locations);
        map.layers.insert(heatMap);
    });