【问题标题】:How to change value on Laravel 5 from function?如何从函数更改 Laravel 5 的值?
【发布时间】:2018-03-20 03:42:36
【问题描述】:

我想问一下 Laravel HTML Collective。 所以我有位置的表格。

所以这张图片来自编辑页面。经纬度是从数据库中获取的。现在我将在搜索地点后更改该值。

我已经制作了谷歌地图 api 函数来获取价值。但现在我很困惑如何更改输入表单。

所以,这是我的功能代码。

function codeAddress(address) {
  geocoder.geocode({
    'address': address
  }, function(results, status) {
    if (status == 'OK') {
      var lng = results[0].geometry.location.lng();
      var lat = results[0].geometry.location.lat();

      console.log('lat:' + lat + ', lng:' + lng);

      if (marker) { marker.setMap(null); }

      marker = new google.maps.Marker({
        position: {
          lat: lat,
          lng: lng
        },
        map: map,
        icon : '{{ url('/images/marker.png') }}'
      });

      map.setCenter( new google.maps.LatLng(lat, lng) );
    } else {
      console.log('Geocode was not successful for the following reason: ' + status);
    }
  });

}

这是我的页面 edit.blade 代码

<div class="row">
      <div class="col-lg-6">
          {{ Form::label('longitude', 'Longitude') }}              
          {{ Form::number(
            'longitude',
            ( isset($db) ) ? $db->longitude : null,
            array(
              'class' => 'form-control'
            )
          ) }}
      </div>
      <div class="col-lg-6">
          {{ Form::label('latitude', 'Latitude') }}                          
          {{ Form::number(
            'latitude',
            ( isset($db) ) ? $db->latitude : null,
            array(
              'class' => 'form-control'
            )
          ) }}
      </div>
    </div>

【问题讨论】:

    标签: function laravel-5 google-maps-api-3 laravel-blade htmlcollection


    【解决方案1】:

    您需要在Laravelblade 中进行一些更改

       {{ Form::number('latitude',( isset($db) ) ? $db->latitude : null,
                array(
                  'class' => 'form-control'
                  'id'=>'latitude' // put this line 
                )
          )
       }}
    
       {{ Form::number('longitude',( isset($db) ) ? $db->longitude : null,
                array(
                  'class' => 'form-control'
                  'id'=>'longitude' // put this line 
                )
          )
        }}
    

    同时更改JS,这将在调用codeAddress(address)时更改纬度,经度。

     map.setCenter( new google.maps.LatLng(lat, lng) );
     $("#longitude").value(lng);
     $("#latitude").value(lat);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-19
      • 2015-10-23
      • 2022-01-12
      • 2015-04-20
      • 2019-02-26
      • 1970-01-01
      • 2015-05-14
      • 2016-08-18
      相关资源
      最近更新 更多