Can't save polygon in google maps

后端 未结 1 1384
小鲜肉
小鲜肉 2021-01-16 11:13

I have a google maps polygon object:

var poly = new google.maps.Polygon({
  paths: [
    new google.maps.LatLng(25.774252, -80.190262),
    new google.maps.L         


        
相关标签:
1条回答
  • 2021-01-16 12:14

    Use google.maps.geometry.encoding.encodePath() to encode the path. This method returns a string, perfect for storing into a DB. For reuse decode the string by using google.maps.geometry.encoding.decodePath()

    Please note: the geometry-library isn't loaded by default, you must load it by appending &libraries=geometry to the src of the maps-API-script.

    To explain why you can't store the path directly(e.g. as JSON):
    when you store the path(array), which contains the LatLng's, you will lose the prototype of the LatLng's, which is essential because it defines the methods for retrieving the properties(lat() and lng() )

    0 讨论(0)
提交回复
热议问题