Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8121719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:35:11+00:00 2026-06-06T05:35:11+00:00

I’m using the Bing Maps Android SDK and I’m looking for a way to

  • 0

I’m using the Bing Maps Android SDK and I’m looking for a way to click on the polygons that I have created and show an infobox. I’ve been able to accomplish this for a pushpin, but not for a polygon. I have seen this answer, but my app needs will make hundreds of such polygons, and I’m looking for a faster solution using the addHandler method on polygons. I know this is possible for the AJAX v7 flavour of the SDK, which is the underlying base of the Android SDK.

The code I tried for the AJAX version (tested using this emulator.)

map.entities.clear(); 
latlon = map.getCenter(); 

var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude+0.15), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15)], null);  
Microsoft.Maps.Events.addHandler(polygon, 'click', DisplayInfo);

map.setView( {zoom:10}); 
map.entities.push(polygon);

function DisplayInfo (e) {
    var vertices = e.target.getLocations();
    var verticeCenter = new Microsoft.Maps.Location(0,0);

    //Calculating location of center
    for (i=0; i<vertices.length-1; i++) {
        verticeCenter.latitude = verticeCenter.latitude + vertices[i].latitude;
        verticeCenter.longitude = verticeCenter.longitude + vertices[i].longitude;
    }
    verticeCenter.latitude = verticeCenter.latitude / (vertices.length - 1);
    verticeCenter.longitude = verticeCenter.longitude / (vertices.length - 1);
    defaultInfobox = new Microsoft.Maps.Infobox(verticeCenter, {width: 200, height: 50} );    
    map.entities.push(defaultInfobox);
}

However, I pushed a similar code to the BingMapsAndroid.js from the assets folder of the SDK, but that doesn’t work. The handler is attached, as I checked using the hasHandler method. Touches are recorded and their lat and long values are sent to the log, but the polygon event is not evoked even when the touch lies inside a polygon.

Polygon test function in BingMapsAndroid.js:

this.PolygonTest = function() {
    _map.entities.clear(); 
    latlon = new Microsoft.Maps.Location(1,1); 
    console.log("Polygon test function");
    var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude+0.15), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15)], null);  

    try {
    Microsoft.Maps.Events.addHandler(polygon, 'click', function(e) { console.log("Polygon click!"); }); //This is never evoked
    Microsoft.Maps.Events.addHandler(_map, 'click', function(e) { var point = new MM.Point(e.getX(), e.getY()); var loc = e.target.tryPixelToLocation(point); console.log("lat: " + loc.latitude + ", lon: " + loc.longitude); });

    } catch(e) {
        alert("Error");
    }

    _map.setView( {zoom:10}); 
    _map.entities.push(polygon);

    if (Microsoft.Maps.Events.hasHandler(polygon,'click')) {
        console.log("Polygon has click handler."); //This works
    }

    //This function should be added to the click handler for polygon. I'll add it when I know the handler works.
    function DisplayInfo (e) {
        console.log("Polygon has been clicked.");
        var vertices = e.target.getLocations();
        var verticeCenter = new Microsoft.Maps.Location(0,0);
        for (i=0; i<vertices.length-1; i++) {
            verticeCenter.latitude = verticeCenter.latitude + vertices[i].latitude;
            verticeCenter.longitude = verticeCenter.longitude + vertices[i].longitude;
        }
        verticeCenter.latitude = verticeCenter.latitude / (vertices.length - 1);
        verticeCenter.longitude = verticeCenter.longitude / (vertices.length - 1);
        defaultInfobox = new Microsoft.Maps.Infobox(verticeCenter, { width: 200, height: 50 });
        _map.entities.push(defaultInfobox);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:35:13+00:00Added an answer on June 6, 2026 at 5:35 am

    After much testing, I found the issue lies in Android. I tried the code on Bing Maps Interactive SDK for AjaxV7 and these are my results:

    • Desktop browsers: works (as written in the question)
    • iPhone 4S: works
    • Android 2.3.4 with default browser: does not work
    • Android 2.3.4 with Opera: works
    • Android ICS with Opera: works
    • Android ICS with default browser: does not work
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.