Con i link correlati ora le coordinate combaciano al pixel.
Il codice seguente ti restituisce 4 variabili con le coordinate in pixel di dove si trovano le località, non dove si trova l'icona che è spostata in alto rispetto alla località di 7 pixel come descritto nell'offset, l'offset cambia se cambi l'icona altrimenti è sempre lo stesso.
Private Declare Function InternetOpen Lib "WININET" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "WININET" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function InternetReadFile Lib "WININET" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "WININET" (ByVal hInet As Long) As Integer
Private Declare Function DeleteUrlCacheEntry Lib "WININET" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Dim pushpin_0_x As Integer
Dim pushpin_0_y As Integer
Dim pushpin_1_x As Integer
Dim pushpin_1_y As Integer
Private Sub Form_Activate()
carica_sito ("http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/Routes?wp.0=37,3107,13,5766;3;AGRIGENTO&wp.1=43,4628,11,8807;9;AREZZO&mapsize=640,480&C=IT&mapMetadata=1&format=jpeg&key=Ap94-koskdt-HryTYKhaJf5GLnuzjt3uLkl5AyKQnIYw6m6QPmiDIxJSWW_1AJ_1")
End Sub
Public Sub carica_sito(url)
Dim hOpen As Long
Dim hOpenUrl As Long
Dim sURL As String
Dim bDoLoop As Boolean
Dim bRet As Boolean
Dim sReadBuffer As String * 2048
Dim lNumberOfBytesRead As Long
sBuffer = ""
sURL = url
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, sURL, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
bDoLoop = True
While bDoLoop
DoEvents
sReadBuffer = vbNullString
bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
Wend
If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
If hOpen <> 0 Then InternetCloseHandle (hOpen)
Text1.Text = sBuffer
Call Interpreta(CStr(sBuffer))
End Sub
Private Sub Interpreta(json As String)
Dim pos1 As Long
Dim pos2 As Long
pos1 = 1
pos1 = InStr(pos1, json, "coordinates", vbTextCompare)
pos2 = InStr(pos1 + 1, json, "]", vbTextCompare)
List1.AddItem ("coordinate centro mappa: " & Mid(json, pos1 + 13, pos2 - pos1 - 12))
pos1 = InStr(pos2, json, "pushpin", vbTextCompare)
pos2 = InStr(pos1 + 1, json, "}", vbTextCompare)
Dim pushpin_0 As String
pushpin_0 = Mid(json, pos1 + 22, pos2 - pos1 - 22)
List1.AddItem ("pushpin_0: " & pushpin_0)
pos1 = InStr(pos2, json, "coordinates", vbTextCompare)
pos2 = InStr(pos1 + 1, json, "]", vbTextCompare)
List1.AddItem ("coordinate_0: " & Mid(json, pos1 + 13, pos2 - pos1 - 12))
pos1 = InStr(pos2, json, "anchor", vbTextCompare)
pos2 = InStr(pos1 + 1, json, "}", vbTextCompare)
Dim pushpin_1 As String
pushpin_1 = Mid(json, pos1 + 9, pos2 - pos1 - 9)
List1.AddItem ("pushpin_1: " & pushpin_1)
pos1 = InStr(pos2, json, "coordinates", vbTextCompare)
pos2 = InStr(pos1 + 1, json, "]", vbTextCompare)
List1.AddItem ("coordinate_1: " & Mid(json, pos1 + 13, pos2 - pos1 - 12))
pos1 = InStr(1, pushpin_0, ":""", vbTextCompare)
pos2 = InStr(pos1, pushpin_0, """,", vbTextCompare)
pushpin_0_x = CInt(Mid(pushpin_0, pos1 + 2, pos2 - pos1 - 2))
List1.AddItem ("pushpin_0_x = " & pushpin_0_x)
pos1 = InStr(pos2 + 2, pushpin_0, ":""", vbTextCompare)
pos2 = InStr(pos1 + 2, pushpin_0, """", vbTextCompare)
pushpin_0_y = CInt(Mid(pushpin_0, pos1 + 2, pos2 - pos1 - 2))
List1.AddItem ("pushpin_0_y = " & pushpin_0_y)
pos1 = InStr(1, pushpin_1, ":""", vbTextCompare)
pos2 = InStr(pos1, pushpin_1, """,", vbTextCompare)
pushpin_1_x = CInt(Mid(pushpin_1, pos1 + 2, pos2 - pos1 - 2))
List1.AddItem ("pushpin_1_x = " & pushpin_1_x)
pos1 = InStr(pos2 + 2, pushpin_1, ":""", vbTextCompare)
pos2 = InStr(pos1 + 2, pushpin_1, """", vbTextCompare)
pushpin_1_y = CInt(Mid(pushpin_1, pos1 + 2, pos2 - pos1 - 2))
List1.AddItem ("pushpin_1_y = " & pushpin_1_y)
End Sub
Metti il Form e la PicturBox,
Form1.ScaleMode = 3 e
Picture1.ScaleMode = 3 così lavori con le coordinate in pixel.
Carica la bitmap nella picturebox e imposta le dimensioni della picturebox in accordo con le dimensioni dell'immagine imageHeight":"480","imageWidth":"640"
ora con:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Caption = X & " - " & Y
End Sub
in X e Y avrai le coordinate che corrispondono con quelle della bitmap, ho messo una label, un test per vedere se hai fatto tutto bene non guasta mai, in alto a sx avrai 0 - 0, in basso a dx avrai 639 - 479.
all'interno della routine MouseMove dovrai scrivere il codice che verifica quando le coordinate corrispondono a quelle delle variabili che ti ho trovato.
un range per evitare di dover puntare un singolo pixel è d'obbligo.