none
Bing Maps v8 migration: Invalid latitude error when using Map Center Offset RRS feed

  • Question

  • I'm trying to migrate the code below but I'm getting an Invalid latitude error - does anything stand out that I'm doing wrong?

    var locations = polygon.getLocations(),
    newZoom = mapsearch.determineZoom(locations),
    rect = MM.LocationRect.fromLocations(locations);
    var loc = rect.center;
    loc = mapsearch.map.tryLocationToPixel(new MM.Location(loc.latitude, loc.longitude));
    loc.x += 50;
    cp = mapsearch.map.tryPixelToLocation(loc);        
    mapsearch.map.setView({zoom: newZoom, center: cp });

    Value of cp variable from above:

    altitude: 0

    altitudeReference: -1

    latitude: 36.93082150000001

    longitude: -76.17105594921875


    Stack trace:
    Error: Invalid latitude
    Stack trace:
    n@https://www.bing.com/rms/MapCoreBundle/cj,nj/ac38c0ee/6fa841c8.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*MapCore.en*MapCoreBegin*LabelOptions*LocalStorageCache*Gimme*GimmeWrapper*evPromise*ExternalPromise*StaticPromise*CookiesHelper*LruCache*Point*Rectangle*NAARectangle*ResourceManager*Anchor*Size*Binding*EventBinding*Observable*ObservableObject*ObservableObjectChangedArgs*ObservableCollection*Debug*DelayLoadedObject*JSEvent*Dispatcher*WorkDispatcher*Iterator*ElementSizeHelper*GimmeExt*GimmeTransition*Helper*PerfState*ClientPerf*LoggingWrapper*LoggerConstants*Network*ThrottledEventInvoker*ObjectPool*StaticObjectPool*FixedSizeObjectPool*OrderedDictionary*PooledImage*Url*MapCoreMiddle*NavigationBarMode*NavigationBarOrientation*TransformCurve*CurveKey*Curve*Color*CurveVector4*CurveColor*Vector4*DiscreteRange*DiscreteRangeCollectionSpline*MapLayer*CopyrightProvider*CopyrightProviderService*CustomMapStyleManager*MapFrameManager*LayerFrameManager*GoalCounter*FrameEventAggregator*DataMonitor*MapFrameData*LayerFrameData*Clipper*CompositePrimitiveSet*DataLoader*Differ*FixedPrimitiveSet*PrimitiveSubset*Overlay*ImageryMapLayer*SimpleSceneContributor*VectorMapLayer*BasicMapAnimation*MapViewAnimator*BoundsAccumulator*CombinedLayerCollection*ConstrainViewArgs*LatLonCrs*LocationRect*Matrix2D*MapInstrumentationManager*PerfV2Logger*Map*MapHelper*MapMath*MapLocation*MapType*MapTypeChangeArgs*MapTypeCollection*MapTypeId*MapView*MapQuadrant*PrimitiveOverlayHelper*OverlayBehavior*GeometryGeneralizer*SimplePointPrimitive*SimpleLinePrimitive*SimpleAreaPrimitive*MoveableSimplePointPrimitive*TargetViewChangeArgs*VectorMath*ViewChangeArgs*ZoomLevel*ZoomAroundLocationAnimator*ZoomEventArgs*OverviewMapMode*MapAuthentication*PublicApi*InternalApi*AnonymousEnd:1:242535
    w</n.getCameraForLocationToPoint@https://www.bing.com/rms/CompositeModeBundle/cj,nj/164052df/8d29ca72.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*CompositeModePluginBegin*Viewport*CompositeMapMode*BoundaryHelper*CompositeModeHelper*ElevationRequest*EnhancedBirdseyeCrs*BirdseyeV2Crs*RegionIndex*HitTestIndex*HitTestController*MercatorCubeCrs*MercatorTileUtility*RasterImageryScene*BirdseyeV2ImageryScene*BirdseyeV2Metadata*RobinsonCubeCrs*CompositeModePluginEnd*AnonymousEnd:1:27424
    lt</n.prototype.getCameraForLocationToPoint@https://www.bing.com/rms/CompositeModeBundle/cj,nj/164052df/8d29ca72.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*CompositeModePluginBegin*Viewport*CompositeMapMode*BoundaryHelper*CompositeModeHelper*ElevationRequest*EnhancedBirdseyeCrs*BirdseyeV2Crs*RegionIndex*HitTestIndex*HitTestController*MercatorCubeCrs*MercatorTileUtility*RasterImageryScene*BirdseyeV2ImageryScene*BirdseyeV2Metadata*RobinsonCubeCrs*CompositeModePluginEnd*AnonymousEnd:1:5488
    gs</n.setMapCenter@https://www.bing.com/rms/MapCoreBundle/cj,nj/ac38c0ee/6fa841c8.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*MapCore.en*MapCoreBegin*LabelOptions*LocalStorageCache*Gimme*GimmeWrapper*evPromise*ExternalPromise*StaticPromise*CookiesHelper*LruCache*Point*Rectangle*NAARectangle*ResourceManager*Anchor*Size*Binding*EventBinding*Observable*ObservableObject*ObservableObjectChangedArgs*ObservableCollection*Debug*DelayLoadedObject*JSEvent*Dispatcher*WorkDispatcher*Iterator*ElementSizeHelper*GimmeExt*GimmeTransition*Helper*PerfState*ClientPerf*LoggingWrapper*LoggerConstants*Network*ThrottledEventInvoker*ObjectPool*StaticObjectPool*FixedSizeObjectPool*OrderedDictionary*PooledImage*Url*MapCoreMiddle*NavigationBarMode*NavigationBarOrientation*TransformCurve*CurveKey*Curve*Color*CurveVector4*CurveColor*Vector4*DiscreteRange*DiscreteRangeCollectionSpline*MapLayer*CopyrightProvider*CopyrightProviderService*CustomMapStyleManager*MapFrameManager*LayerFrameManager*GoalCounter*FrameEventAggregator*DataMonitor*MapFrameData*LayerFrameData*Clipper*CompositePrimitiveSet*DataLoader*Differ*FixedPrimitiveSet*PrimitiveSubset*Overlay*ImageryMapLayer*SimpleSceneContributor*VectorMapLayer*BasicMapAnimation*MapViewAnimator*BoundsAccumulator*CombinedLayerCollection*ConstrainViewArgs*LatLonCrs*LocationRect*Matrix2D*MapInstrumentationManager*PerfV2Logger*Map*MapHelper*MapMath*MapLocation*MapType*MapTypeChangeArgs*MapTypeCollection*MapTypeId*MapView*MapQuadrant*PrimitiveOverlayHelper*OverlayBehavior*GeometryGeneralizer*SimplePointPrimitive*SimpleLinePrimitive*SimpleAreaPrimitive*MoveableSimplePointPrimitive*TargetViewChangeArgs*VectorMath*ViewChangeArgs*ZoomLevel*ZoomAroundLocationAnimator*ZoomEventArgs*OverviewMapMode*MapAuthentication*PublicApi*InternalApi*AnonymousEnd:1:238878
    tt</n.prototype.setView@https://www.bing.com/rms/SDKPlugin/cj,nj/2465735d/d3748bc1.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*SDKPluginStart*SDKInfoboxOverlay*Infobox*SDKColor*TileSource*TileLayer*Module*Layer*EntityCollection*Events*SDKPrimitiveTemplateSelector*UserMouseEventArgs*PixelReference*Pushpin*SDKPolygon*SDKPolyline*TestDataGenerator*CustomOverlay*AnimatedTileLayer*MapsTilePrimer*SDKMap*PointCompression*SDKPluginEnd*AnonymousEnd:1:76630
    @http://evansm.homes.com/HomesCom/Resources/Javascript/prod/jquery-1.8.3.min.js?v=20160301 line 2 > eval:131:18
    c@https://www.bing.com/rms/SDKPlugin/cj,nj/2465735d/d3748bc1.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*SDKPluginStart*SDKInfoboxOverlay*Infobox*SDKColor*TileSource*TileLayer*Module*Layer*EntityCollection*Events*SDKPrimitiveTemplateSelector*UserMouseEventArgs*PixelReference*Pushpin*SDKPolygon*SDKPolyline*TestDataGenerator*CustomOverlay*AnimatedTileLayer*MapsTilePrimer*SDKMap*PointCompression*SDKPluginEnd*AnonymousEnd:1:16617
    g</n._createInstance/<@https://www.bing.com/rms/SDKPlugin/cj,nj/2465735d/d3748bc1.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*SDKPluginStart*SDKInfoboxOverlay*Infobox*SDKColor*TileSource*TileLayer*Module*Layer*EntityCollection*Events*SDKPrimitiveTemplateSelector*UserMouseEventArgs*PixelReference*Pushpin*SDKPolygon*SDKPolyline*TestDataGenerator*CustomOverlay*AnimatedTileLayer*MapsTilePrimer*SDKMap*PointCompression*SDKPluginEnd*AnonymousEnd:1:17842
    c/<@http://www.bing.com/api/maps/mapcontrol?callback=GetMap:12:6854
    e@http://www.bing.com/api/maps/mapcontrol?callback=GetMap:12:2226
    r/<@http://www.bing.com/api/maps/mapcontrol?callback=GetMap:12:2603
    _onstatechange@http://www.bing.com/api/maps/mapcontrol?callback=GetMap:12:4226


    • Edited by kmshel73 Monday, May 22, 2017 12:33 PM
    Monday, May 22, 2017 1:14 AM

Answers

  • Looking at the current site, it doesn't look like this is doing much of anything. I would recommend skipping this process and simply setting the view this way:

    var rect = MM.LocationRect.fromLocations(polygon.getLocations());
    mapsearch.map.setView({ bounds: rect });


    [Blog] [twitter] [LinkedIn]

    Monday, May 22, 2017 7:55 PM

All replies

  • Looking at your code, it doesn't look like it would do as you expect as the tryLocationToPixel and tryPixelToLocation uses the current map views zoom level to calculate the pixel values. If the map was at zoom level 1 and you this calculation you will offset the pixels by 50 at that zoom level which would be about 3900KM. If the zoom level you actually wanted was say 10, the 50 pixel offset would be a distance of about 8km, however, this would not be the value you would be getting using your code.

    Can you explain what it is you are trying to do. Looking at your code I'm guessing this:

    1. You have a polygon and want to display that map so it is in view. 
    2. For some reason you want to offset the center of the view by 50 pixels. Why? This would put part of the polygon out of view. 


    [Blog] [twitter] [LinkedIn]

    Monday, May 22, 2017 4:55 PM
  • Thanks for your input - the original developer that worked on our map is no longer with the company, but I can see from the commit history that the reasoning was "offset map center when zooming when clicking clusters" - so I believe it must have been to fix a specific display bug.

    Here is a link to an example of our map  http://www.homes.com/for-sale/norfolk-va/map/

    * update - I tried commenting out the loc.x += 50; but it still returns the same Invalid latitude error message



    • Edited by kmshel73 Monday, May 22, 2017 5:59 PM
    • Marked as answer by kmshel73 Monday, May 22, 2017 8:14 PM
    • Unmarked as answer by Ricky_Brundritt Monday, May 22, 2017 11:16 PM
    Monday, May 22, 2017 5:14 PM
  • Looking at the current site, it doesn't look like this is doing much of anything. I would recommend skipping this process and simply setting the view this way:

    var rect = MM.LocationRect.fromLocations(polygon.getLocations());
    mapsearch.map.setView({ bounds: rect });


    [Blog] [twitter] [LinkedIn]

    Monday, May 22, 2017 7:55 PM
  • Thank you! 
    Monday, May 22, 2017 8:14 PM