简体   繁体   English

如何在gmap3中通过纬度经度设置位置

[英]how setting a location by latitude longitude in gmap3

good afternoon, I am using the plugin gmap3 ( http://gmap3.net ), and I am not able to set the location where you will center the map and display the marker. 下午好,我正在使用插件gmap3( http://gmap3.net ),但是我无法设置将地图居中并显示标记的位置。

Explanation: I save the value of latitude and longitude in the database. 说明:我将纬度和经度的值保存在数据库中。 For example "-29.165708760531277, -51.51253212137226". 例如“ -29.165708760531277,-51.51253212137226”。 and another screen, I want to open showing that location. 和另一个屏幕,我要打开以显示该位置。 I'm trying to do this: 我正在尝试这样做:

   var localizacao = $("#localizacao").text();

        $("#mapEditar").gmap3({
          marker:{
            latLng: [localizacao],
              draggable:true
            },
          },
          map:{
            options:{
              zoom: 16,
              mapTypeId:google.maps.MapTypeId.HYBRID,
            }
          }
        });

where the variable "localizacao", this value will be the longitude latitude. 此处的变量“ localizacao”为经度。

But using this way, it is not showing the map. 但是使用这种方式,它不会显示地图。 Is there a better way to do this? 有一个更好的方法吗? What do am I doing wrong? 我做错了什么?

thank you 谢谢

Well to start it looks like you have an extra curly brace in your code 好吧,它看起来好像您的代码中有一个大括号

var localizacao = $("#localizacao").text();

$("#mapEditar").gmap3({
      marker:{
        latLng: [localizacao],
          draggable:true
        },
      //}, REMOVED
      map:{
        options:{
          zoom: 16,
          mapTypeId:google.maps.MapTypeId.HYBRID,
        }
      }
    });

And for why latLng is not working with [localizacao] , it is because latLng takes two separate parameters separated by a comma, like ["-29.165708760531277", "-51.51253212137226"] . 以及为什么latLng无法与[localizacao]一起使用的原因,是因为latLng采用了两个用逗号分隔的独立参数,例如["-29.165708760531277", "-51.51253212137226"] The variable localizacao contains a string in the form "-29.165708760531277, -51.51253212137226" which results in ["-29.165708760531277, -51.51253212137226"] , which won't work because there is only one parameter. 变量localizacao包含形式为“ -29.165708760531277,-51.51253212137226”的字符串,其结果为["-29.165708760531277, -51.51253212137226"] ,该["-29.165708760531277, -51.51253212137226"]将不起作用,因为只有一个参数。

var lat = $("#localizacao_lat").text();
var lng = $("#localizacao_lng").text();

$("#mapEditar").gmap3({
      marker:{
        latLng: [lat, lng],
          draggable:true
        },
      map:{
        options:{
          zoom: 16,
          mapTypeId:google.maps.MapTypeId.HYBRID,
        }
      }
    });

Here's a JSFiddle that might help :) 这是一个JSFiddle ,它可能会有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM