0

緯度と経度の座標があり、Web ブラウザー インスタンスで Google ストリートビューまたは Bing ストリートサイドを開こうとしています。

以下のGoogleストリートビューのURLを使用してこれを行うことができましたが、座標が正確に道路上にない場合、機能しないことがわかりました. 代わりに、全世界の地図を取得します。

string.Format(
    "http://maps.google.com/?cbll={0},{1}&cbp=12,0,0,0,5&layer=c",
    this.Location.Latitude,
    this.Location.Longitude)

使用したい座標はロンドンにあるため、ほぼすべてマップされています。最寄りの通りの場所を表示したいと思います。

4

3 に答える 3

4

私が過去に行ったことは、このようなものです。指定された場所から 50 メートル以内に StreetViewService の「パノラマ」があることを確認します。そのまま動作する完全なサンプル JS コードを次に示します。

<!DOCTYPE html>
<html>
<head>
<title>Streetview</title>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#streetView { height: 100%; width: 100%; }
</style>

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

<script type="text/javascript">

    function createStreetMap(strMapCanvasID, intLat, intLong)
    {
        //create a google latLng object
        var streetViewLocation = new google.maps.LatLng(intLat,intLong);
        var panorama;

        //once the document is loaded, see if google has a streetview image within 50 meters of the given location, and load that panorama
        var sv = new google.maps.StreetViewService();

        sv.getPanoramaByLocation(streetViewLocation, 50, function(data, status) {
            if (status == 'OK') {
                //google has a streetview image for this location, so attach it to the streetview div
                var panoramaOptions = {
                    pano: data.location.pano,
                    addressControl: false,
                    navigationControl: true,
                    navigationControlOptions: {
                        style: google.maps.NavigationControlStyle.SMALL
                    }
                }; 
                var panorama = new google.maps.StreetViewPanorama(document.getElementById(strMapCanvasID), panoramaOptions);
            }
            else{
                //no google streetview image for this location, so hide the streetview div
                $('#' + strMapCanvasID).parent().hide();
            }
        });

        return panorama;
    }

    $(document).ready(function() {
        var myPano = createStreetMap('streetView', 51.513016, -0.144424);
    });
</script>

</head>
<body>
<div>
    <h2>Street View</h2>
    <div id="streetView"></div>
</div>
</body>
</html>

そして、DOM がロードされた後にのみ、この関数を呼び出します (それ以外の場合、関数内からすぐに実行しようとするとエラーが見つかりましたinitialize)。

$(document).ready(function() {
    var myPano = createStreetMap('streetView', someLatitude, someLongitude);
});

createStreetMap内部からの呼び出しを使用する代わりに C# を使用すると、 WebBrowser.InvokeScriptメソッドを使用して、次のようなことを行うことができると思います$(document).ready(function() { ... });

object[] args = {"streetView",51.513016,-0.144424};
webBrowser1.Document.InvokeScript("createStreetMap",args);

参照: http://www.codeproject.com/Tips/60924/Using-WebBrowser-Document-InvokeScript-to-mess-aro

于 2013-01-31T14:56:56.063 に答える
1

以前は、URL を操作して Google マップの操作を行っていました。WebBrowserそれは、C#インスタンスから JavaScript を呼び出す機能を発見するまで続きました。通常、Google Maps APIWebBrowserInvokeScriptメソッドを使用して、必要なものを呼び出します。場合によっては面倒になることもありますが、はるかに用途が広いことがわかりました。

編集: 申し訳ありませんが、それは必ずしもあなたの質問に対する直接的な回答ではないことを認識していますが、最も基本的な地図操作以外の場合、API と JavaScript がはるかに優れた機能を提供することを発見しました。

于 2013-01-31T14:45:44.853 に答える