Access Google Maps?

dev82

New member
Local time
Today, 14:13
Joined
Oct 12, 2010
Messages
6
Hello Folks,

i have this database. how can i create more adresses in the form. to display 100 adresses.

thanks
Dev82
 

Attachments

Servus and Welcome to the forum.

That is a cool example I assume you got it somewhere. Where? :-)

You need to understand this here - Show Card (KartenAnzeige)



Code:
Function KartenAnzeige()
On Error GoTo fehler
Dim doc As WebBrowser, str As String, strK(10) As String, strI As String
Dim strOrt(10) As String, strStrasse(10) As String, strHausnummer(10) As String, strPLZ(10) As String

For i = 1 To 3
    If i = 1 Then
        strI = ""
    Else
        strI = i
    End If
    
    Me("Strasse" & strI).SetFocus
    If Me("Strasse" & strI).Text = "" Then
        If i = 1 Then Exit Function
        Exit For
    End If
    strStrasse(i) = Me("Strasse" & strI).Text
    
    Me("Hausnummer" & strI).SetFocus
    strHausnummer(i) = Me("Hausnummer" & strI).Text
    
    Me("PLZ" & strI).SetFocus
    strPLZ(i) = Me("PLZ" & strI).Text
    
    Me("Ort" & strI).SetFocus
    If Me("Ort" & strI).Text = "" Then
        If i = 1 Then Exit Function
        Exit For
    End If
    strOrt(i) = Me("Ort" & strI).Text

'Konvertierung zu UTF-8
'**********************
    Dim kl As New Klasse1
    strOrt(i) = kl.ANSIToUTF8(strOrt(i)): strStrasse(i) = kl.ANSIToUTF8(strStrasse(i))

'Koordinaten ermitteln
'**********************
'    lat = 0: lon = 0
    strK(i) = GetAddressCoord(strStrasse(i) & "+" & strHausnummer(i) & "+" & strOrt(i))
'    strL = lat & "," & lon
'    strK2 = GetAddressCoord(Me!Strasse2 & " " & Me!Hausnummer2 & " " & Me!Ort2, AccStreet, lat, lon)
'    strL2 = lat & "," & lon
'    strK3 = GetAddressCoord(Me!Strasse3 & " " & Me!Hausnummer3 & " " & Me!Ort3, AccStreet, lat, lon)
'    strL3 = lat & "," & lon
Next i
Me!Zoom.SetFocus
If Me!Zoom.Text = "" Or IsNull(Me!Zoom) Then
    Me!Zoom.Text = intZoom
End If

'Kartenausschnitt ausgeben
'*************************
str = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">" & vbCrLf & _
"<html>" & vbCrLf & _
  "<head>" & vbCrLf & _
    "<meta http-equiv=""content-type"" content=""text/html; charset=UTF-8""/>" & vbCrLf & _
    "<title>Google Maps</title>" & vbCrLf & _
    "<script src=""http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAPDUET0Qt7p2VcSk6JNU1sBSM5jMcmVqUpI7aqV44cW1cEECiThQYkcZUPRJn9vy_TWxWvuLoOfSFBw"" type=""text/javascript""></script>" & vbCrLf & _
  "</head>" & vbCrLf & _
  "<body onunload=""GUnload()"">" & vbCrLf & _
    "<div id=""map"" style=""width: 425px; height: 350px""></div>" & vbCrLf & _
    "<noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b>" & vbCrLf & _
      "However, it seems JavaScript is either disabled or not supported by your browser." & vbCrLf & _
      "To view Google Maps, enable JavaScript by changing your browser options, and then" & vbCrLf & _
      " try again." & vbCrLf & _
    "</noscript>" & vbCrLf & _
    "<script type=""text/javascript"">" & vbCrLf & _
    "//<![CDATA[" & vbCrLf & _
    "if (GBrowserIsCompatible()) {" & vbCrLf & _
      "function createMarker(point,html) {" & vbCrLf & _
        "var marker = new GMarker(point);" & vbCrLf & _
        "GEvent.addListener(marker, ""click"", function() {" & vbCrLf & _
          "marker.openInfoWindowHtml(html);"
          str = str & vbCrLf & _
        "});" & vbCrLf & _
        "return marker;" & vbCrLf & _
      "}" & vbCrLf & _
      "var map = new GMap2(document.getElementById(""map""));" & vbCrLf & _
      "map.addControl(new GLargeMapControl());" & vbCrLf & _
      "map.addControl(new GMapTypeControl());" & vbCrLf
      str = str & _
      "map.setCenter(new GLatLng(" & strK(1) & ")," & Me!Zoom & ");" & vbCrLf & _
      "var point = new GLatLng(" & strK(1) & ");" & vbCrLf & _
      "var marker = createMarker(point,'<div style=""width:240px"">Some stuff to display in the First Info Window. With a <a href=""http://www.econym.demon.co.uk"">Link<\/a> to my home page<\/div>')" & vbCrLf & _
      "map.addOverlay(marker);" & vbCrLf & _
      "var point = new GLatLng(" & strK(2) & ");" & vbCrLf & _
      "var marker = createMarker(point,'Some stuff to display in the<br>Second Info Window')" & vbCrLf & _
      "map.addOverlay(marker);" & vbCrLf & _
      "var point = new GLatLng(" & strK(3) & ");" & vbCrLf & _
      "var marker = createMarker(point,'Some stuff to display in the<br>Third Info Window')" & vbCrLf & _
      "map.addOverlay(marker);" & vbCrLf & _
    "}"
    
    'display a warning if the browser was not compatible
    str = str & "else {" & vbCrLf & _
      "alert(""Sorry, the Google Maps API is not compatible with this browser"");" & vbCrLf & _
    "}" & vbCrLf & _
    "</script>" & vbCrLf & _
  "</body>" & vbCrLf & _
"</html>"

Open "C:\temp\temp.htm" For Output As #1
    
    Print #1, str

Close #1
'FollowHyperlink "C:\temp\temp.htm"
'Exit Function
Set doc = ctlWeb.Object
doc.Navigate "C:\temp\temp.htm"
'doc.Document.body.innerHTML = str
Exit Function
fehler:
Debug.Print Err.Description, Err.Number
'If Err.Number <> 2475 Then
'Resume Next
End Function
First you would need to change this part "For i = 1 To 3" to maybe "For i = 1 To N" with N being the number of records or addresses you have.

Then the loop will loop through ok (provided you follow his nameing convention of text boxes) so you are right then till "Kartenausschnitt ausgeben"

Here the person is making a HTML website that hosts the Google Maps API and then on the fly takes this text and puts it into a file "C:\temp\temp.htm"

Then the webbrowser is pointed to this file.

Unfortunately the person has hard coded this part for only 3
Code:
"var point = new GLatLng(" & strK(1) & ");" & vbCrLf & _
and then later there is a strK(2) and strK(3). You will have to create this part of the string creation into a loop similar to the above. So that this text is created "N" times.

One word of warning about this example. I am pretty sure that one of the Terms and Conditions of Google Maps and Google earth is that you are only allowed to use it if you give public/free access to your website hosting the maps/earth. By using C drive you are not doing this. There is some tolerance because people have to test things, but I think that Google might do something if their API is used like this often for a long time. (I honestly dont know the repercussions or if there are any)
 
sehe gerade du kommst aus München.
aber bin Australier. :-)

You will have to create this part of the string creation into a loop similar to the above

You will have to create a loop for this stuff as well. See that he currently hard codes "strK(1)"...

strK is an array - look up what that is. Now cause he only uses 3 addresses he can use strK(1) strK(2) strK(3). In the code when he makes his HTML. You need to change this to a For i = 1 To N (where N is the number of addresses you have.

Then use strK(i) instead.

so this section here
Code:
"map.setCenter(new GLatLng(" & strK(1) & ")," & Me!Zoom & ");" & vbCrLf & _
      "var point = new GLatLng(" & strK(1) & ");" & vbCrLf & _
      "var marker = createMarker(point,'<div style=""width:240px"">Some stuff to display in the First Info Window. With a <a href=""http://www.econym.demon.co.uk"">Link<\/a> to my home page<\/div>')" & vbCrLf & _
      "map.addOverlay(marker);" & vbCrLf & _
      "var point = new GLatLng(" & strK(2) & ");" & vbCrLf & _
      "var marker = createMarker(point,'Some stuff to display in the<br>Second Info Window')" & vbCrLf & _
      "map.addOverlay(marker);" & vbCrLf & _
      "var point = new GLatLng(" & strK(3) & ");" & vbCrLf & _
you need to change to only once and instead of fixed numbers you replace it for (i).

Does that make sense.
 
wow, great from australia. how is the weather now?

i have tested it, dosen't work. he show's me an error. a number is needed.
 

Attachments

I'm in Munich and the weather is actually Great. After the Wies'n the weather is always good. :-)

I see your new example and I SO WISH computer coding was that easy. Sorry it is not.

Lets take this slow. Where are you going to get your 100 addresses from? I assume a table? Is that correct? Is the table structure the same as in your example.

I would suggest you go back to your old example as it is working and we will change that. I am not an expert so I am not going to give you the answer but I will work with you.

If you are using a table then can you start your new function like KartenAnzeige - call it showcard


Code:
Function ShowCard()
On Error GoTo fehler
Dim doc As WebBrowser, str As String, strK(10) As String, strI As String
Dim strOrt(10) As String, strStrasse(10) As String, strHausnummer(10) As String, strPLZ(10) As String





Exit Function
fehler:
Debug.Print Err.Description, Err.Number
'If Err.Number <> 2475 Then
'Resume Next
End Function

First you need to create a RecordSet from your table of your addresses.
You need to be able to get the number of records in that record set
You need to create Arrays that can accept variable numbers of strings (currently they are fixed)
Once you have that post the example again or ask me a question.
 
i'm near frankfurt, the weather here is also great.

the records are from a table.

my access skills aren't so good. i don't know how to create this arrays sorry.
 
my access skills aren't so good. i don't know how to create this arrays sorry.

I would prefer that you learn as we do this. I can do this but you need to learn.

Have a go at opening your database, getting a record set and then looping through records. There are thousands of examples here.

something like this- but you cannot cut and copy this.

Code:
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim sql As String

sql = "SELECT * FROM yourtable WHERE yourcritera;"

Set DB = CurrentDb
Set RS = DB.OpenRecordset(sql, dbOpenDynaset)
Then you need to get the number of records that your record set holds. You need this because the arrays you are going to make will have to be this number as well. Then look up dynamic arrays. We will have to create the size of our array on the fly.

Once you have this we can then put this to work with the exisiting code.

Dont worry once you get started and have questions you can always ask them here. But have a go.
 
hello again,

i created the code like this:
Code:
Public Function createRecordset(strAdressen As String) As DAO.Recordset
    Dim rs As DAO.Recordset
    Dim db As DAO.Database
   
    Set db = CurrentDb
    Set rs = db.OpenRecordset(strAdressen)
    set createRecordset = rs
End Function
but i don't know what is that sense behind that? could you explain it me?

thanks
Carsten
 
but i don't know what is that sense behind that? could you explain it me?

thanks
Carsten
I am not going to spoon feed you buddy - leaning is not an option.

Google is your friend. Google.com not de

I have already written this above but here again.

1. You need to get a list of all your addresses - this is done with a recordset. You now need to learn how to loop through each record in RS
2. Then you need to add each record to the existing arrays in the code. You will need to have dynamic arrays of a non-fixed size as your number of addresses may change. Have a look around this is also very common and there are many examples.
3. Once you have this then you can use the arrays to add the information to build that long string which will then be the "on the fly website".

These steps alone a pretty basic stuff and we need to take it step by step so that you learn how to change it in the future.

Once you can do 1 2 3 and you have code I will help you to fit it together.
 

Users who are viewing this thread

Back
Top Bottom