Connecting strings togther

rfresh

Well-Known Member
Licensed User
Longtime User
I'm trying to build a URL string using the following

mGoogleMap = "http://maps.google.com/maps?q=" & pLatMap & "," & pLongMap

The var pLatMap = 33.000000

but when used to make the URL string, it comes out as 3.000000 meaning the first char is missing but I don't know why.

Any help appreciated...
 

Jost aus Soest

Active Member
Licensed User
Longtime User
With the assumption of
B4X:
Dim pLatMap, pLongMap As Float
Dim mGoogleMap As String
I get the expected result:
B4X:
http://maps.google.com/maps?q=33,0
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Gosh, I wonder why I don't...:sign0148:

Hmmm...so I can string together Floats with Strings?

mGoogleMap = "http://maps.google.com/maps?q=" & pLatMap & "," & pLongMap
 
Last edited:
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
I use the Log feature to see that the Lat and Long vars are correct and they are. Then I email the whole URL string to myself and that's where the first char (the 3) of the lat is missing when I view the body of the email.
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
I've discovered the problem is with the '=' char in the URL string:

mGoogleMap = "http://maps.google.com/maps?q=" & pLatMap & "," & pLongMap

If I remove the = char and email myself the URL the pLatMap string has the 33. correctly. So I think this means I need to escape the URL string right?
 
Last edited:
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
If you escape the = you may lose the meaning of it in the url depending on how it is escaped. URL Escaping would make it a character and not mean a separator for your GET variables. I don't think = would need escaping either, or at least it hasn't in other languages. If so it is usually with a slash (/ or \ whichever B4A uses...I just started coding in it) You could try isolating it putting it in its own quotes with & concatenating it, or maybe converting/casting the floats to strings and see if that helps. I use that very same string to pull Google Map locations in PHP and C# without converting or escaping anything.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I've discovered the problem is with the '=' char in the URL string:

mGoogleMap = "http://maps.google.com/maps?q=" & pLatMap & "," & pLongMap

If I remove the = char and email myself the URL the pLatMap string has the 33. correctly. So I think this means I need to escape the URL string right?

It seems there's a bug in that lib when a string has a "q=", search the forums and youl will find the thread and you'll see the workaround.
 
Last edited:
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
I'm attaching a small test app that shows this problem. The lat string is 33.7669 and when the URL is built in the app, it is correct and Logs correctly but when the email is sent out (using gmail) when you open the email, that first char of the Lat string 33.7669 is missing so you end you end up with just 3.7669.

The problem char is the = char but I don't know how to fix this.

Thanks...
 

Attachments

  • gpstest.zip
    5.6 KB · Views: 201
Last edited:
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
It seems there's a bug in that lib when a string has a "q=", search the forums and youl will find the thread and you'll see the workaround.

Thanks NJDude but I can't find the post with the workaround. I tried searching on q= and = bug and url bug but nothing was found?
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Yes, thanks for the help. Adding that fake attachment solved the problem for me.
 
Last edited:
Upvote 0
Top