0
Public Class Geocode
Public Structure GeocodeResult
    Public Latitude As String
    Public Longitude As String
    Public Result As String
End Structure


Public Shared Function GetGeocode(ByVal Address As String) As GeocodeResult
    Dim strLat As String = ""
    Dim strLon As String = ""
    Dim strResult As String = ""
    Dim oXmlDoc As Object
    GetGeocode.Latitude = ""
    GetGeocode.Longitude = ""
    GetGeocode.Result = ""
    Try
        Dim baseURL As String = "https://maps.google.com/maps/api/geocode/xml?sensor=false&address=" & Address
        baseURL = Replace(baseURL, " ", "+")
        oXmlDoc = CreateObject("Microsoft.XMLDOM")
        With oXmlDoc
            .Async = False
            If .Load(baseURL) And Not .selectSingleNode("GeocodeResponse/status") Is Nothing Then
                GetGeocode.Result = .selectSingleNode("GeocodeResponse/status").Text
                If Not .selectSingleNode("GeocodeResponse/result") Is Nothing Then
                    GetGeocode.Latitude = .selectSingleNode("//location/lat").Text
                    GetGeocode.Longitude = .selectSingleNode("//location/lng").Text
                    Return GetGeocode
                End If
            End If
        End With
        oXmlDoc = Nothing
        Return GetGeocode
        Exit Function
    Catch ex As Exception
        Throw (ex)
    End Try
    Return GetGeocode
End Function
End Class

これは、Azure VM に移動するまで、運用環境、qa、および localhost で正常に動作します。VM からブラウザーを使用してhttps://maps.google.com/maps/api/geocode/xml?sensor=false&address= URL にアクセスできます。しかし、別のページが getgeocode 関数を呼び出すと、結果は常に空白になり、残りの API 呼び出しが何らかの形で失敗したことを意味します。

a)この呼び出しでキーを使用していないため、およびb)Google APIキーを任意のドメインに設定してテストしているため、ドメインキーの制限ではないと思います。編集:同じ結果で別のサービスを使用してみました。開発環境とローカル マシンでは機能しますが、Azure VM では機能しません。私が理解していないのは、ブラウザー経由で REST API にアクセスする方法ですが、コードから呼び出されたときに何も返さないということです。何か案は?

4

1 に答える 1