Erase data from Google Maps

1

I have an ionic app that makes use of google maps. In this map I display information that the user provides. For example: The user wants to make a report that will appear on the map. However, if the user, at another time, wants to make another complaint, the new information should appear. So I need to delete the old information to display the new information. How can I do this?

My code in angular:

.controller('MapaResCtrl', function($scope, $rootScope) {

$rootScope.diaDenun;
$rootScope.hora;
$rootScope.tipo;
$rootScope.des;
$rootScope.coordenadas;


var mapOptions = {
    zoom: 16,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map"), mapOptions);

navigator.geolocation.getCurrentPosition(function(pos) {
    map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
    $rootScope.myLocation = new google.maps.Marker({
        position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude),
        map: map,
        title: "My Location",
        //animation:google.maps.Animation.BOUNCE
    });
    var infowindow = new google.maps.InfoWindow({
            content: "Dia da denúncia "+$rootScope.diaDenun+" Hora: "+$rootScope.hora+" Tipo: "+$rootScope.tipo+" Descrição: "+$rootScope.des
      });

    infowindow.open(map,$rootScope.myLocation);
});

$scope.map = map;

})

Print how information appears on the map:

    
asked by anonymous 07.04.2016 / 20:30

2 answers

2

Your interface implementation with Google Maps does not require any changes.

Values are being read from variables created in $rootScope :

var infowindow = new google.maps.InfoWindow({
            content: 
            "Dia da denúncia "+ $rootScope.diaDenun + 
            " Hora: " + $rootScope.hora +
            " Tipo: " + $rootScope.tipo + 
            " Descrição: "+$rootScope.des
      });

If you want to display other values, check the part of your code that populates the properties diaDenun , hora , tipo , and des $rootScope .     

07.04.2016 / 20:41
0

Every marker has a map set to it. To remove the map marker, you need to set the map to null . This way:

$rootScope.myLocation.setMap(null);

See a detailed example at: link

    
07.04.2016 / 20:49