如何让if-else显示Geolocation按钮[Laravel 5.2]?

时间:2016-08-23 05:49:31

标签: javascript laravel-5.2

如果用户位置在半径范围内,我想显示一个按钮。

我正在使用https://packagist.org/packages/anthonymartin/geo-location创建半径。

在控制器中:

public function location()
{

  $edison = GeoLocation::fromDegrees(-7.5656511,110.8623398);
    $coordinates = $edison->boundingCoordinates(0.1, 'miles');


    echo "min latitude: " . $coordinates[0]->getLatitudeInDegrees() . " \n";
    echo "min longitude: " . $coordinates[0]->getLongitudeInDegrees() . " \n";

    echo "max latitude: " . $coordinates[1]->getLatitudeInDegrees() . " \n";
    echo "max longitude: " . $coordinates[1]->getLongitudeInDegrees() . " \n";

/**
    *   Returns:
    *   min latitude: -7.567098415559
    *   min longitude: 110.86087977441 
    *   max latitude: -7.564203784441
    *   max longitude: 110.86379982559
    **/
   }

JavaScript to getCurrentPosition:

  <script>
var x = document.getElementById("demo");

function getLocation() {
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
} else {
    x.innerHTML = "Geolocation is not supported by this browser.";
}
}

function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>

查询是什么:

If user location in radius (latitude and longtitude) 
echo <button></button>
else
"Too far away from location"

0 个答案:

没有答案