0

我想问一下 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>
4

1 回答 1

-1

您需要在Laravel刀片中进行一些更改

   {{ 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);
于 2018-03-20T04:14:37.123 回答