JavaScript how to draw google map rectangle if I only know its size and northeast point draw rectangle google maps,draw rectangle google earth

to draw a rectangle in google map, I need to know northwest and southeast points to construct a LatLngbounds first.

In my situation, I want to draw a rectangle with specific northwest point and a size (say 100 meters width and 100 meters height). I do not know the southest point.

I am afraid of geometry and geology. I know the southeast can be derived from some fomulas. Just want to know whether there is api or easy ways to do that?

Answer:1

You can write a function like this:

// Given the LatLng of a northwest corner, and the number of meters to
// measure east and south, return the LatLngBounds for that rectangle
function makeBounds( nw, metersEast, metersSouth ) {
    var ne = google.maps.geometry.spherical.computeOffset(
        nw, metersEast, 90
    );
    var sw = google.maps.geometry.spherical.computeOffset(
        nw, metersSouth, 180
    );
    return new google.maps.LatLngBounds( sw, ne );
}

Here's a working example.

Answer:2

I am extending Backbone views like: var baseView = Backbone.View.extend({ fruits : [], listFruits : function() { console.log(this.fruits); } }); var firstView = baseView.extend({ ...

I am extending Backbone views like: var baseView = Backbone.View.extend({ fruits : [], listFruits : function() { console.log(this.fruits); } }); var firstView = baseView.extend({ ...

  1. backbone view inheritance

I have a controller, simplified for brevity: .controller('myCtrl', ['$scope', 'data', function ($scope, data) { $scope.myVar = testFunction(data.name); function testFunction (name) { ... }; ...

I have a controller, simplified for brevity: .controller('myCtrl', ['$scope', 'data', function ($scope, data) { $scope.myVar = testFunction(data.name); function testFunction (name) { ... }; ...

  1. jasmine test scope variable
  2. angularjs test scope variable
  3. test-path variable scope
  4. junit test variable scope
  5. java test variable scope
  6. javascript test variable scope

I am trying to replace all the content, depending on what it is, with a corresponding unicode character in all anchors that are descendants of the class nav ( .nav a ). But this javascript / jQuery ...

I am trying to replace all the content, depending on what it is, with a corresponding unicode character in all anchors that are descendants of the class nav ( .nav a ). But this javascript / jQuery ...

Can anyone please help me how to do this? I would like to pass the message from the websocket to the serial port every time I receive a message var firmata = require('firmata'); var board = new ...

Can anyone please help me how to do this? I would like to pass the message from the websocket to the serial port every time I receive a message var firmata = require('firmata'); var board = new ...

  1. javascript message passing
  2. javascript message passing between windows