phpangularjslaravelng-admin

ng-admin and google maps


I am working on a project that uses ng-admin as framework and I am totally new with angular, etc.

The thing is that I need to use google maps with that, because I have one Entity with Latitude and Longitude.

But I have no idea about how I'm gonna do that. here's what I have done:

gstation.creationView()
.fields([
     nga.field('latitude')
        .validation({ required: true }),
     nga.field('longitude')
        .validation({ required: true }),
     nga.field('fk_company', 'reference')
         .isDetailLink(false)
         .label('Company')
         .targetEntity(companies)
         .targetField(nga.field('name'))
]);

I don't know if there's an easy way to do that or if I need to do that my way.

I can always start something to make that work, but I don't want to create something my way, instead of follow a pattern (if exists).

Any ideas?

Thank you.


Solution

  • Just to complement the answer of @Vikas..

    I could make that work by changing to this:

    myApp.directive('geocode', ['$location', function ($location) {
    return {
        restrict: 'E',
        scope: {
            geocode: '=bind',
        },
        link: function($scope, uiGmapIsReady) {
            var iLat, iLong;
            if ($scope.geocode && $scope.geocode.latitude !== undefined)    {
                iLat  = parseFloat($scope.geocode.latitude);
                iLong = parseFloat($scope.geocode.longitude);
            } else {
                iLat  = 19.090555;
                iLong = 72.888684;
                $scope.geocode = new Object;
                $scope.geocode.__type = "GeoPoint";
                $scope.geocode.latitude = iLat;
                $scope.geocode.longitude = iLong;
            }
    
            var maps = { center: { latitude: iLat, longitude: iLong }, zoom: 12 };
    
            $scope.map = maps;
            $scope.options = {scrollwheel: false};
    
            $scope.marker = {
                id: 0,
                coords: {
                    latitude: iLat,
                    longitude: iLong
                },
                options: { draggable: true },
    
                events: {
                    dragend: function (marker, eventName, args) {
                        $scope.geocode.latitude  = marker.getPosition().lat();
                        $scope.geocode.longitude = marker.getPosition().lng();
                        var latlng = {lat: parseFloat($scope.geocode.latitude), lng: parseFloat($scope.geocode.longitude)};
    
    
                        $scope.marker.options = {
                            draggable: true,
                            labelContent: $scope.address,
                            labelAnchor: "100 0",
                            labelClass: "marker-labels"
                        };
    
                    }
                }
            };
    
        },
        template: 
        `
        <div class="row list-view">
            <div class="col-lg-12">
                <ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options" pan=true  refresh="true">
                    <ui-gmap-marker coords="marker.coords" options="marker.options" events="marker.events" idkey="marker.id">
                    </ui-gmap-marker>
                </ui-gmap-google-map>
            </div>
        </div>
        `
    };}]);
    myApp.config(function (uiGmapGoogleMapApiProvider) {
    uiGmapGoogleMapApiProvider.configure({
        key: '',
        v: '3',
        libraries: 'visualization'
    });});