Creating a Google map with multiple markers within a 10 km radius of the current location in a rectangular shape

Currently, I am working on a web application that utilizes Google Maps and AngularJS. One of the requirements is to display multiple markers on the map, but only those within a 10km range from the corners, not in a circular radius. In order to achieve this, I am using map.getBounds() to obtain the latitude and longitude of all corners. As I am still new to AngularJS, any assistance would be greatly appreciated.

Answer №1

If you're looking to implement ng-repeat, take a look at this code snippet. While I'm not entirely sure if it's error-free, the concept remains the same:

// html
<div ng-controller="mapCtrl as vm">
<ng-map zoom="15" center="vm.center">
    <marker ng-repeat="position in vm.positions"
            position="{{position.pos}}"
            title="pos: {{position.pos}}">
    </marker>
</ng-map>


// js
angular.module('app').controller('mapCtrl', function() {
    var vm = this;

    var markersCount = 10;
    var distanceBetweenMarkers = 0.01;

    vm.center = [40, -70];
    vm.positions = [];

    for(var i = 0; i < markersCount; i += 1) {
        var leftMarker = [vm.center[0] - distanceBetweenMarkers, vm.center[1]];
        var rightMarker = [vm.center[0] + distanceBetweenMarkers, vm.center[1]];

        vm.positions.push(leftMarker);
        vm.positions.push(rightMarker);
    }
});

Hopefully, this solution gives you some direction. Feel free to reach out if you have any further questions. 😊
Thank you. 😊

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adding HTML content using jQuery's document.ready feature

As a jQuery novice, I am attempting to incorporate a Facebook like button using the jQuery document.ready function. In my external Javascript file (loaded after the jQuery script), you will find the following code snippet: $(document).ready(function(){ ...

Only one instance of the Next.js inline script is loaded

Incorporating Tiny Slider into my Next.js application has been a success, but I am facing an issue with the inline script that controls the slider's behavior. The script loads correctly when I first launch index.js. However, if I navigate to another p ...

Lunar - incorporate route parameter into DOM query_operation

Is there a way to take a route parameter and use it to trigger a click event on a DOM element? The issue is that onBeforeAction is called before the DOM is fully loaded. Any suggestions on how to solve this problem? JS onBeforeAction: function(){ var ...

Incorporating a setup file into my JavaScript project

In my JavaScript project, I have both frontend and backend codes (NodeJS). Here is the folder structure for my production environment: /prod /server sourceCode1.js sourceCode2.js ... sourceCodeN.js index.js ...

What steps do I need to take in order to implement a recursive function that keeps track of the history of local variables

Check out this cool function that takes a multi-dimensional array and converts it into a single-dimensional array using recursion. It's pretty nifty because it doesn't use any global variables, so everything is contained within the function itsel ...

AngularJS: How can I eliminate the #! from a URL?

Looking for guidance on how to remove #! from the URL in AngularJS using ng-route. Can anyone provide a step-by-step process on removing #!? Below is the code snippet: index.html <head> <script src="https://ajax.googleapis.com/ajax/libs/ang ...

Ensuring that only one field is selected with mandatory values using Joi validation

Is there a way to create a validation rule utilizing Joi that ensures if valueA is empty, then valueB must have a value, and vice versa? My current approach involves using Joi for validating an array of objects with properties valueA and valueB. Below is ...

Exploring the benefits of utilizing useState and localStorage in Next.js with server-side

Encountering an error consistently in the code snippet below: "localstorage is not defined" It seems like this issue arises because next.js attempts to render the page on the server. I made an attempt to place the const [advancedMode, setAdvanced ...

Error Encountered: Unexpected Identifier in Angular 7 External jQuery Plugin

Struggling to convert a jQuery template to Angular7, I'm facing an issue with loading .js files from the assets folder in the original template to make it functional. Upon starting the application with: ng serve, I encounter the following error in th ...

Utilizing selection and ng-options with a personalized filter in Angular 1.x

Introduction Recently, I created a unique filter that eliminates currently selected options from the list of available options for multiple <select> inputs. Check it out on CodePen - http://codepen.io/jusopi/pen/XdjNWa?editors=1010 Implementation ...

When downloading files in Chrome or Safari, the $ajax call is in a pending state, whereas in IE or Firefox,

Measuring the time it takes to download a 1MB file using AJAX calls. Below is the code snippet: var start = new Date(); $(document).ready(function() { $.ajax ({ url: 'https://www.example.com/dummyFile1024', crossDomain: t ...

Leverage the power of JavaScript strings within PHP

In my JavaScript code, I have a string variable. <script type="text/javascript"> Var string='String to use'; </script> Now I need to retrieve the text from the string variable in PHP. What is the best way to access or utilize it? ...

``In JavaScript, the ternary conditional operator is a useful

I am looking to implement the following logic using a JavaScript ternary operation. Do you think it's feasible? condition1 ? console.log("condition1 pass") : condition2 ? console.log("condition2 pass") : console.log("It is different"); ...

Every Dynamic Post automatically defaults to the initial object

I am currently developing an app that retrieves feeds from a Wordpress site and displays individual posts in a jQuery mobile list format. Here is the JavaScript code I am using: $(document).ready(function () { var url = 'http://howtodeployit.com/ ...

What are the steps to convert a canvas element, using an image provided by ImageService as a background, into a downloadable image?

I've been working on an app that allows users to upload an image, draw on it, and save the result. To achieve this functionality, I'm using a canvas element with the uploaded image as its background. The image is retrieved through ImageService. B ...

Searching patterns in Javascript code using regular expressions

I am dealing with two strings that contain image URLs: http://dfdkdlkdkldkldkldl.jpg (it is image src which starts with http and ends with an image) http://fflffllkfl Now I want to replace the "http://" with some text only on those URLs that are images. ...

Stuck on AMChart while trying to load data

Hello! I am currently utilizing the AMCharts framework to generate charts from data stored in a MySQL database. However, I have encountered an issue where instead of displaying the chart, I am stuck with a perpetual "Loading Data" message. You can view a ...

JavaScript function to convert a string of characters into a readable time format

Is there a way to input a string in an 'input type="time"' field in my HTML code? <label class="item item-input"> <span class="input-label">Departure Time </span> <input type="time" ng-model="heur ...

streamlined method for accessing page parameters in nested components using the next.js application router

In my next.js application, I have a deep hierarchy of nested components. I currently use the params.lang parameter for translations, but I find myself passing it down to every nested component. Although there are hooks available, I prefer rendering them ...

What is the reason behind the warning "Function components cannot be given refs" when using a custom input component?

When attempting to customize the input component using MUI's InputUnstyled component (or any other unstyled component like SwitchUnstyled, SelectUnstyled, etc.), a warning is triggered Warning: Function components cannot be given refs. Attempts to acc ...