Creating personalized markers in Angular using Google Maps Icon customization

Having trouble displaying a custom icon instead of the default one on my map.

html

<ui-gmap-google-map center="vm.map.center" zoom="vm.map.zoom" options="options">
<ui-gmap-marker icon="vm.options.icon" coords="vm.marker.coords" events="vm.marker.events" idkey="vm.marker.id">
</ui-gmap-marker>
 </ui-gmap-google-map>

controller

  var vm = this;


    vm.map = {
        center: {
            latitude: 43.6042600,
            longitude: 1.4436700
        },
        zoom: 10
    };

vm.options = {icon:'images/location.png'};
    vm.coordsUpdates = 0;
    vm.dynamicMoveCtr = 0;
    vm.marker = {
        id: 0,
        coords: {
            latitude: 43.6042600,
            longitude: 1.4436700
        },
        events: {
            dragend: function(marker, eventName, args) {
                var lat = marker.getPosition().lat();
                var lon = marker.getPosition().lng();
                $log.log(lat);
                $log.log(lon);
                vm.marker.options = {
                    draggable: false,
                    labelContent: "",
                    labelAnchor: "100 0",
                    labelClass: "marker-labels"
                };
            }
        }
    };

Answer №1

To add a custom icon, you can utilize the code snippet below:

  var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    icon: 'url_of_your_custom_image.png'
  });

For more detailed instructions, refer to the Google Maps documentation where they provide guidance on how to customize a map marker.

Answer №2

icon= '{url:"addyourlinkhere" }

The icon should be treated as an object

Answer №3

To customize the icon, you can utilize the `options` attribute within the `ui-gmap-marker` directive

Example

angular.module('appMaps', ['uiGmapgoogle-maps'])

    .config(function (uiGmapGoogleMapApiProvider) {
        uiGmapGoogleMapApiProvider.configure({
            key: ''
        });
    })
    .controller('mapCtrl', function ($scope, uiGmapIsReady) {
        $scope.map = { center: { latitude: 40.1451, longitude: -99.6680 }, zoom: 4, bounds: {} };
        $scope.options = { scrollwheel: false };

        $scope.marker = {
            id: 0,
            coords: {
                latitude: 40.1451,
                longitude: -99.6680
            },
            options: {
                draggable: false,
                icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'
            },
            events: {}
        };

    });
.angular-google-map-container {
   height: 320px;
}
 <script src="https://code.angularjs.org/1.3.14/angular.js"></script>
 <script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
 <script src="https://rawgit.com/angular-ui/angular-google-maps/2.0.X/dist/angular-google-maps.js"></script>
 <div ng-app="appMaps" ng-controller="mapCtrl">
    <ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options">
        <ui-gmap-marker coords="marker.coords" options="marker.options" events="marker.events" idkey="marker.id">
        </ui-gmap-marker>
    </ui-gmap-google-map>
  </div>

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

In Internet Explorer 11, the input event in VueJS may not be triggered upon the first input

I am working with an input HTML element that has @input="onInput" assigned to it. Within the onInput method, I have console log output set up, specifically I am logging event.currentTarget.value. However, I've noticed a strange behavior in IE11 - whe ...

Uploading a file to a .NET Framework API Controller using React

I am trying to figure out how to send files in the request body to an API controller in .NET framework using React. My goal is to achieve this without changing the request headers, so I want to send it as application/json. What I am looking for is somethi ...

update the value of a global variable within a jQuery function

Currently, I am facing an issue with a global variable in jQuery. Here is my code snippet: var namep = ''; $("#page2").bind('pageshow', function (event , data) { var perso = $(this).data("url").split("?")[1]; perso_name = perso. ...

Having trouble getting Vue to properly focus on an input field

I am attempting to use this.$refs.cInput.focus() (cInput being a ref) but it seems to not be functioning as expected. I expect that when I press the 'g' key, the input field should appear and the cursor should immediately focus on it, allowing me ...

Passing a string to a function in AngularJS through ng-click

How can I pass a string to a function using ng click? Here's an example: HTML <a class="btn"> ng-click="test(STRING_TO_PASS)"</a> Controller $scope.test = function(stringOne, stringTwo){ valueOne = test(STRING_TO_PASS); } Edit - ...

Every time I refresh the page, the user is automatically logged out

I am currently working on developing an admin dashboard using nextjs 13. I have encountered a specific issue where the user is redirected to the login page every time they reload the page. Upon inspecting in developer mode, I noticed that cookies are still ...

Maya model being loaded using Three.js

I've been following a tutorial on how to load Maya models using Three.js, which you can find here. Everything is going smoothly, but the tutorial only covers loading models with a single texture. Below is the source code snippet from the tutorial: ...

Implementing Dynamic Passing of Link Element Value to a Function in jQuery

I'm working with a link element that has its value set dynamically through asynchronous means. This label's value will initially be null until it is asynchronously set by an ajax call. <a href="#" onclick="myFunction(**I want to pass the lab ...

Error: The method `push` within the `useHistory` function is causing an issue and is currently undefined

Whenever the home button is clicked, I need it to redirect to the homepage '/ '. However, I keep encountering this error. Any suggestions on what steps I should take to resolve this? : import { Route, useHistory } from 'react-router-dom/cjs/ ...

The functionality of the UI Bootstrap custom directive controller does not seem to be recognized

I am trying to implement UI Bootstrap Collapse within my custom directive called <collapse> Unfortunately, I am encountering the following error: Error: [ng:areq] Argument 'CollapseDemoCtrl' is not a function, got undefined You can view m ...

Managing form submissions using Material UI and Next.js

Can someone provide insights on using Material UI with Next Js? I am experimenting with a Login template from Material UI, but I am facing an issue where query params are added to the URL upon Submit. For example: localhost:3000/auth/login changes to: ...

Navigate to the following section on an HTML page by clicking a button using jQuery

Within my application using Jquery / Javascript, I am looking to implement a specific functionality. I currently have several div elements like the ones below: <div id="div1"></div> <div id="div2"></div> <div id="div3"></ ...

Vue's datepicker displays the date value as '1969'

I recently integrated the Vue datepicker component by following the guide provided at: https://github.com/ReproNim/reproschema-ui/blob/master/src/components/Inputs/YearInput/YearInput.vue After answering the component, if I navigate away from the page and ...

Challenges arising from bower installations within the layout.jade file

Exploring the mean stack as a newcomer, I recently made a change from importing Angular from CDN to using Bower in my layout.jade file. Unfortunately, this adjustment caused my app to malfunction. I encountered a "ReferenceError: angular is not defined" an ...

Tips for updating an Observable array in Angular 4 using RxJS

Within the service class, I have defined a property like this: articles: Observable<Article[]>; This property is populated by calling the getArticles() function which uses the conventional http.get().map() approach. Now, my query is about manually ...

Tips for dynamically unloading an AngularJS directive when switching between templates

My web app is developed using AngularJS and it consists of multiple routes, controllers, and views. Some of the views in my app require specific directives that I have included. However, I have observed that even when I change the route and load a new tem ...

Convert radio input and label into a clickable URL text

Apologies for my lack of experience. I am simply trying to wrap my head around something. <span class="button"> <input type="radio" id="button-2" name="button-group-1"> <label onclick="changeButton('2');" f ...

Transferring information to a subordinate view

I'm working on developing a single-page application and need to transfer data to a child view. After fetching the API using Axios, I am able to successfully log the data in the console. However, when trying to display the data in the child view, I en ...

Retrieve information from a JSON file using a Node.js server

As a JavaScript beginner, I am trying to figure out how to fetch data from a JSON object located on my localhost. Is there a better way to accomplish this task? fetch('http://localhost:3000/show') .then(result => { console.log( ...

Display an array containing date objects in a dropdown menu for users to select from

I am working with an API call that returns an array of objects. Each object in the array contains a date or timestamp in ISO format. Right after my render() method, I have the following code snippet: const pickerItems = this.props.currentData.trips.map(t ...