开发者

Add a parameter to a google maps geocoder function

开发者 https://www.devze.com 2023-02-03 15:41 出处:网络
I want to create a geocoder function, which write the result to it\'s parameter. function geoCode(latlng,div) {

I want to create a geocoder function, which write the result to it's parameter.

  function geoCode(latlng,div) {
    gc.geocode({'latLng': latlng}, function (result, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      new google.maps.Marker({
        position: result[0].ge开发者_开发知识库ometry.location,
        map: map
      });
      $(div).html(result[0].formatted_address);
    }            
  });

How can I add the div parameter to the geocoder function?

Like this:

gc.geocode({'latLng': latlng, writeHere: div}, function (result, status) {
...
$(writeHere).html(result[0].formatted_address);
}

But it's doesn't working.

Any help would be appreciated.


Try with this:

function geoCode(latlng, div) {
    var $div = jq(div);
    gc.geocode({
        'latLng': latlng
    }, function(result, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            new google.maps.Marker({
                position: result[0].geometry.location,
                map: map
            });
            $div.html(result[0].formatted_address);
        }
    });
}
0

精彩评论

暂无评论...
验证码 换一张
取 消