1

私はジオロケーションでいくつかのことをしようとしています。地理位置情報の緯度と経度を 1 つの変数で配列として取得したいと考えています。うまくいきません。コードの最初の行が問題だと思います。そのような値を取得することは可能ですか (リターンあり)?

startingPoint = navigator.geolocation.getCurrentPosition(onGeoSuccess);

function onGeoSuccess(position) {
    start['lat'] = position.coords.latitude;
    start['lng'] = position.coords.longitude;
    return start;
}

より良い解決策はありますか?onGeoSuccess で他のコードを実行したくありません。値を返したいのです。

4

2 に答える 2

1

次のようなことを試すことができます:

function geolocate() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var geolocation = new google.maps.LatLng(
        position.coords.latitude, position.coords.longitude);
      var circle = new google.maps.Circle({
        center: geolocation,
        radius: position.coords.accuracy
      });
      autocomplete.setBounds(circle.getBounds());
    });
  }
}
于 2015-01-26T18:18:45.633 に答える
0

Geolocation がサポートされているかどうかを確認し、次のようなコードを実行します

function getLocation()
  {
  if (navigator.geolocation)//check for support
    {
    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; 
  }
于 2013-04-17T11:37:42.100 に答える