Return from Opoligono

Asked

Viewed 53 times

0

I have Poligono locations saved in a BD. I return these locations to Javascript by a JSON like this:

    [{"lat":"-21.9838014173847","lng":"-49.409637451171875"},{"lat":"-20.3034175184893","lng":"-45.410614013671875"},{"lat":"-23.725011735951796","lng":"-44.180145263671875"},{"lat":"-24.966140159912964","lng":"-48.574676513671875"}]

I am recording this information in the variable var newCoods, so that I need to return this Poligono on screen when the button Visualizaris clicked. The return method is being done as follows:

    var returnPolygon = new google.maps.Polygon({
        map: map,
        paths: newCoords,
        strokeColor: '#FFD700',
        strokeWeight: 3,
        fillColor: '#FFD700',
        fillOpacity: 0.10
    });
    returnPolygon.setMap(map);

When I click the button to make the return, I am passed the following error:

   Uncaught mc {message: "not an Array", name: "InvalidValueError", stack: "Error↵    at new mc ..."}

How should I pass the parameters for polygon return?

  • Look for in your code some variable called "mc", if it is not in your code, must be some problem in the Google Maps API. But for testing purposes, use this example from Google Maps API - Simple Polygon and see if it works. If the error still occurs, analyze the rest of your code better.

  • @Douglasgarrido putting the locations hard code, it works. It only doesn’t work when it takes the ready BD string, even without the " " between the JSON elements. The variable mc does not belong to my code, but to an API property. I have done it in many ways and nothing has worked so far, but as I said, if you put hard code locations, it works.

  • How strange. Check the moment you call new google.maps.Polygon, if a has value in the variable newCoords and what the value is. Use Console browser.

  • Douglas, I’ve done this type of test too, and yes, the variable returns in value perfectly, but if sent to JS as array, in the error it asks for a objeto, send as objeto complete, it tells me it’s not an array, so the question...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.