下記のようなjavascriptの関数からphpに値を渡したいです。
<script> // 現在地を取得 navigator.geolocation.getCurrentPosition( // 取得成功した場合 function(position) { // 現在地の緯度・経度 var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); var geocoder = new google.maps.Geocoder; geocoder.geocode({ 'location': latlng }, function(results, status) { document.getElementById('location').innerHTML = (results[0].formatted_address); }); } ); </script> 現在地は:<span id="location"></span>
下のようなコードを書いても関数の場合は値を渡せず、関数の中に入れてしまうと動きません。
<?php $latitude="<script>document.write(position.coords.latitude);</script>"; echo $latitude; ?>
現在地を把握して、SQLの座標を近い順にPHPで並べ替えたいのですが、うまく値を渡すにはどのようにすればよいでしょうか。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。