How to add a rectangle to google maps using java on visual studio code platform ?

sharon glipman 441 Reputation points
2023-02-19T09:57:16.69+00:00

This is my java file:

and i tried to add the rectangle but the result is a long endless rectangle to the west and east and what i wanted to do is to add a small rectangle to the current lat and lng.

i tried to do it like this example : https://developers.google.com/maps/documentation/javascript/examples/rectangle-simple#maps_rectangle_simple-javascript

the result is :

result1

function initMap() {
    // The location of Uluru
    const uluru = { lat: 32.1582615544072, lng: 34.89155037133181 };

    // The map, centered at Uluru
    const map = new google.maps.Map(document.getElementById("map"), {
      zoom: 11,
      center: uluru,
      disableDefaultUI: true,
    });

    const rectangle = new google.maps.Rectangle({
        strokeColor: "#FF0000",
        strokeOpacity: 0.8,
        strokeWeight: 2,
        fillColor: "#FF0000",
        fillOpacity: 0.35,
        map,
        bounds: {
          north: 32.165,
          south: 32.151,
          east: 34.883,
          west: 34.990,
        },
      });
}
  
  window.initMap = initMap;
Developer technologies Visual Studio Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2023-02-19T11:14:55.11+00:00

    Try a different order:

    east: 34.990,
    west: 34.883,
    

0 additional answers

Sort by: Most helpful

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.