Custom icons in Angular Google Maps are effective only when the marker is refreshed

After initially adding a marker with a default icon, I noticed that upon updating its location, it transforms into a custom icon as desired.

map.html

<ui-gmap-google-map center="map.center"
            control="map.control"
            zoom="map.zoom"
            options="map.options"
            bounds="map.bounds"
            draggable="true">
    <ui-gmap-markers
            models="markerArray"
            coords="'self'"
            icon="'icon'">
    </ui-gmap-markers>
</ui-gmap-google-map>

map.js/addMarker (adds a marker with default icon)

function addMarker(markerId, latitude, longitude, icon, iconSize) {

    markerIconSize = new google.maps.Size(iconSize[0],iconSize[1]);

    var marker = {
        id: markerId,
        latitude: latitude,
        longitude: longitude, 
        icon: {
            url: icon,
            scaledSize: markerIconSize
        }
    };
    $scope.markers.push(marker);
    $scope.markerArray = $scope.markers;
}

map.js/updateMarker (updates the coordinates and uses custom icon)

function updateMarker(markerId,latitude,longitude) {

     var marker = _.find($scope.markerArray, function(marker) {
          return marker.id = markerId;
     });

     marker.latitude = latitude;
     marker.longitude = longitude;
}

Answer №1

One idea that comes to mind is: First, try manually inputting the icon URL to see if it resolves the issue. Next, attempt separating out the marker declaration like this:

var marker;
var markerOptions = {
    id: markerId,
    latitude: latitude,
    longitude: longitude, 
    icon: {
        url: iconUrl,
        scaledSize: markerIconSize
    }
};
marker = new google.maps.Marker(markerOptions);
$scope.markers.push(marker);
$scope.markerArray = $scope.markers;

This method helped me solve my map issues, so I thought of sharing it with you. Hopefully, it proves beneficial for your situation too.

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

Function not triggered as a listener for a scroll event when the React hook is not updated

My function handleScroll listens for the scroll event and is supposed to update the value of isFetching, toggling its boolean value from false to true. Despite the fact that the function handleScroll is being listened to correctly, as indicated by the con ...

What is the reason for XMLHttpRequest.status being equal to 0 in all browsers except for Internet Explorer?

I am encountering a frustrating issue... After developing a standalone RESTful.NET webservice using C#, I noticed that when I make a XMLHttpRequest to fetch JSON data, all browsers, except for IE, fail to retrieve the data. The problem lies in the status ...

Using jQuery to extract all image sources from a parent element and remove a portion of the source URLs

I need to extract all the img src attributes from a parent element using a pointer in order to remove part of them. When I have an image selected, the src ends with _selected.jpg. Then, when I click on a link containing another image, I want to remove the ...

Creating a new image by extracting a specific HTML div tag that contains an image and its layers

I currently have a div element that includes an image element along with multiple other div elements containing small text displayed above the image. I am looking to save the image along with its content to a new image file. Any suggestions or ideas are ...

Utilize Angular's ng-repeat directive to iterate through this JSON data structure for implementing user-to

Struggling with the user-to-user messaging interface on an app and having difficulty using ng-repeat on the items. Here is the provided data: { "ID": 4118, "CreatedDate": "2015-08-20T03:12:50.397", "recipient": [ { ...

Encountering issues with creating a session in Selenium/webdriver while utilizing Safari 12

Ever since making the update to Safari 12, my automated scripts have been encountering a new error: SessionNotCreatedError: Request body does not contain required parameter 'capabilities'. (Interestingly, this error is exclusive to Safari and d ...

Is it possible to pass a variable from an Axios Response in the Composition API up to the root level?

I need to fetch the headings array from an axios.get call and utilize it at the root level within my Vue component. However, when I attempt to return it, I encounter this error: ReferenceError: headings is not defined Here is the script element in my Vue3 ...

Tips for managing submitted data to a server in express?

In the process of sending a post request from my index.js to app.js upon a click event, I have the following code snippet: var data = { name: "Sarah", age: "21" }; var xhr = new XMLHttpRequest(); xhr.open("POST", "/", true); xhr.setRequestHe ...

"Need some tips on how to make the body animate downwards when toggling the

Just starting out and trying to teach myself how to code. I've come across an issue where my Navbar-collapse is now overlapping the content of my page, and this time it's a problem because I want the background of the navbar-collapse to be transp ...

What is the best way to disable the button hover effect after it has been clicked?

Many posts I've come across have similar issues to mine, but the suggested solutions are not working for me. I am struggling to remove the hover property of my button when it is clicked before triggering the removal event I have set up. Edit: Just t ...

Utilizing nested arrays to implement v-for loop for efficient data rendering

Within my array - 'items', each object contains another array of objects. I am trying to retrieve the second array called 'productPrices' in order to use v-for. However, items.productPrices is not working for me. Do I need to implement ...

Having issues with the functionality of the Previous/Next button in my table

I am facing a challenge with my table as I am trying to include previous/next button for users to navigate through it. However, the interaction doesn't seem to be functioning properly, and I suspect that I need to establish a connection between the bu ...

Showing JSON response on an HTML page using AngularJS

I have limited experience with JavaScript and/or Angular, but I am required to utilize it for a research project. My task involves showcasing the JSON data returned by another component on a webpage. Here is how the process unfolds: When a user clicks on ...

I'm looking for a tag cloud widget that can handle JSON objects. Any suggestions?

Looking for recommendations on widgets that can generate a tag cloud using JSON objects. I have an array of JSON objects and would like to know the most effective method for creating a tag cloud with them. Thanks in advance! =) ...

Unable to modify the .Css file for the VueJs plugin

I've been utilizing the vue-js-modal plugin and inside, there is a style.css file. I attempted to customize the modal style by making changes to this file, but even after saving my modifications and running the application, the modal page still reflec ...

The behavior of Mozilla in handling JQuery attr() function may result in variations in design elements such as font-family or font-size

I'm currently working on the login form. Below is my view in CodeIgnitor: <div id="login-form"> <?php echo heading('Login', 2); echo form_open('login/login_user'); echo form_input('email', set_value ...

Efficiently executing mutations on a constantly updating list of objects

For my particular scenario, when a user provides an array of files as input, the application will simultaneously initiate the upload process for each file and display a component representing each ongoing upload. I attempted to use the useMutation hook fro ...

Example: Utilizing data transfer from model to directive

I have a question regarding a specific part in an example from Thinkster. I believe my confusion is due to my limited understanding of JavaScript and AngularJS fundamentals. I've been teaching myself since December, starting with the basics of JavaScr ...

Determine the precise boundaries of the React component

I am working with a basic ellipse element: <span style={{ width: /*someWith*/, height: /*someHeight*/, borderRadius: "50%" }}/> and, I am using getBoundingClientRect() to retrieve its bounds (displayed in blue). https://i.ssta ...

The property 'get' cannot be accessed due to its undefined or null reference

I have encountered a seemingly simple issue while working on my project. The error message I am receiving is: Unable to get property 'get' of undefined or null reference This error occurs when I try to make a call to my API from the controller ...