JavaScript update markers from JSON on google maps update markers on google maps,after effects update markers from

Django 1.8 and python 2.7. I am trying to update the location of a marker using jQuery and Ajax.

My json object has only one array:

[{"latitud": "55.75222", "ciudad": "Moscu", "longitud": "37.61556"}]

After initialize the map, I create this function in order to set the marker and also I used setTimeout to get the new marker position.

function setMarker(map) {

    $.getJSON('http://127.0.0.1:8000/maps/car/gpspos/', function(userPos) {
        userLat = userPos["userPosView"][0].latitud;
        userLon = userPos["userPosView"][0].longitud;
        var position = new google.maps.LatLng(userLat,userLon);
        var marker = new google.maps.Marker({
            position: position,
        });
        marker.setMap(map)


        // A function that checks if the user has a new position and set marker there
        $(document).ready(function(){
            setTimeout(function() {
                (marker.getPosition());
            },5000);
        });
    });
}

The result is that I can not get the new position when a new latitud and longitud values are entered to the db. I would be grateful is somebody could help me

Answer:1

Save the previous lat, long in a variable, and check it when you are asking again to the db.

var lat, lng;

function setMarker(map) {

    $.getJSON('http://127.0.0.1:8000/maps/car/gpspos/', function(userPos) {
        userLat = userPos["userPosView"][0].latitud;
        userLon = userPos["userPosView"][0].longitud;
        if(lat == null){ lat = userLat; }
        if(lng == null){ lng = userLat; }
        if(userLat != lat && userLon != lng){
            lat = userLat;
            lng = userLong;

            //do stuff
            Console.log("lat lng changed");
        }
        var position = new google.maps.LatLng(userLat,userLon);
        var marker = new google.maps.Marker({
            position: position,
        });
        marker.setMap(map)
    });
}

I guess you are asking to db calling the setMarker method.

Answer:2

OK I have full expectation of going down in flames for asking something stupid (or at least duplicate), but in the attached snippet, why do I have to use window.getComputedStyle to access styles ...

OK I have full expectation of going down in flames for asking something stupid (or at least duplicate), but in the attached snippet, why do I have to use window.getComputedStyle to access styles ...

A) Are there any resources of how to use server-side javascript without Node.js? B) Can a java-based server communicate with a javascript-based client? Both options are okay (I would be more happy ...

A) Are there any resources of how to use server-side javascript without Node.js? B) Can a java-based server communicate with a javascript-based client? Both options are okay (I would be more happy ...

  1. server side javascript
  2. server side javascript object
  3. server side javascript tutorial
  4. server side javascript frameworks
  5. server side javascript marketing cloud
  6. server side javascript injection
  7. server side javascript example
  8. server side javascript w3schools
  9. server side javascript is also known as
  10. server-side javascript has stopped working
  11. server side javascript tutorial pdf
  12. server side javascript is known as
  13. server side javascript rendering
  14. server-side javascript remote code execution
  15. server side javascript is also called as
  16. server-side javascript code injection
  17. server side javascript injection payloads
  18. server side javascript vs php
  19. server side javascript salesforce
  20. server side javascript injection example

I'm loading data from saved session using: componentDidMount() { if (JSON.parse(localStorage.getItem('savedData')) !== null) { this.setState({ cartItems: JSON.parse(...

I'm loading data from saved session using: componentDidMount() { if (JSON.parse(localStorage.getItem('savedData')) !== null) { this.setState({ cartItems: JSON.parse(...

is there some simple way how to read POST request parameters in nuxtjs asyncData function? Thanks a lot. Here's an example: Form.vue: <template> <form method="post" action="/clickout" ...

is there some simple way how to read POST request parameters in nuxtjs asyncData function? Thanks a lot. Here's an example: Form.vue: <template> <form method="post" action="/clickout" ...

  1. read post request python
  2. read post request php
  3. read post request node js
  4. read post request body c#
  5. read post request flask
  6. read post request body java
  7. read post request javascript
  8. read post request c#
  9. read post request
  10. read post request java
  11. read post request body javascript
  12. php read post request body
  13. golang read post request
  14. express read post request body
  15. arduino read post request
  16. django read post request
  17. express read post request
  18. read json post request java
  19. esp8266 read post request
  20. node read post request