点击按钮后如何在地图上显示位置?

时间:2016-09-12 05:14:00

标签: javascript php html

我有字段文本,按钮和地图的代码:

<div class="input-group">
  <span class="input-group-addon" id="basic-addon1" onclick="get_location(this)"><i class="fa fa-map-marker" aria-hidden="true"></i></span>
  <input type="text" name="et_full_location" id="et_full_location" class="text-field input-item required" placeholder="<?php _e("Enter your place's address", ET_DOMAIN); ?>" />
</div>

<input type="hidden" name="et_location_lat" id="et_location_lat" class="text-field input-item " />
<input type="hidden" name="et_location_lng" id="et_location_lng" class="text-field input-item " />
<style type="text/css">#map{height:200px !important;width:95%!important;margin-top:10px!important;}</style>
<div id="map" style=""></div>
<span style=" font-size: 0.8em; font-style: italic;"><?php _e("Drag the marker to specify correct coords.", ET_DOMAIN); ?></span>

我的地图代码显示如下:

enter image description here

如果我输入该字段位置,我的地图会显示我输入的位置,这是正常的,但是当我尝试从左侧点击GeoLocation图标时,我的功能将位置放在字段中,但地图并没有工作(不显示我的位置)。如果我按下按钮时没有输入,我的地图总是有效。我该怎么办?

我的位置功能是:

<?php
        $ip = $_SERVER['REMOTE_ADDR'];
        $details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));

        $country = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));

        $address =  $details->city . " " . $country->region;

?>
<script type="text/javascript">

    function get_location(element)
    {
        document.getElementById('et_full_location').value = "<?php echo $address; ?>";
    }    

</script>

0 个答案:

没有答案