Can I retrive Lat,Long from Webview of Google Maps Centre Home Example?

BarrySumpter

Active Member
Licensed User
Longtime User
Does anyone have sample VB code for extracting lat, lng from google Centre is Home?
Google Maps API v3

I've had a good look at this example:
//google-developers.appspot.com/maps/documentation/javascript/examples/control-custom-state
https://google-developers.appspot.com/maps/documentation/javascript/examples/control-custom-state

Allows you to centre the map
Then set Home as Centre of the map
move the map to display elsewhere
then your can click Home to return Home.



and read thru the b4a forum posts using google maps examples.

But none seem to do what I'm after.

-----

Since, on my phone, trying to pin point a specific place my touching the map, is hard work my fat fingers, I've found its easier to place a pin point in the middle of my phone screen and move the map behind. To align the position I want to pin point behing the center point.

I've got a server so my bike riding buddies can find me at a new coffee shop or a kick off place. They can log their GPS and I can watch them find me.

But I actually have to be there waiting for them for my app to record its gps.

I'd like to use a pin in the middle of my phone display.
And move the map around behind it.
Positioning the coffee shop address or the kickoff place along the bike path of were we are going to meet in an hour or tomorrow or next saturday.

Then be able to capture that lat, lng and send it my server so they and I can plan our route etc.

That example of google maps html is very close but I can't find a way to extract the lat,lng from it.

Does anyone have a coding example to extract the lat,lng by positioning the map behind a center point on the phone screen in this manner?

As always, I'm happy to chase down any leads and post my solution.

tia
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Me too, but I discovered there are some missing files in the zip. I don't remember now, maybe in Object/res/drawable. Look at examples before 5 and you'll see what is missing in examples 6 and above. Copy and paste ...
Marco

Checked that before.'
Checked again just now.
No diff in file names.
Content of specific files may be different.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
...

Let me know if renaming the downloaded tiles is not possible or practical and also then let me know exactly how the downloaded tiles are named and i'll see what i can do.

...

Thanks for the offer Martin.

Silly me for thinking thinking it was going to be just a simple v4a code change. I see now its probably a library change.

If you could see what you can do, that would be great.

Attached maps in the format downloaded.
Two zip files to reduce upload sizes to forum retstrictions.

I can name the folders to whatever fits in with your OSMDroid v3.2

But the file names come as they are named in the ziped sample.

the _list, _log. and _egmd files contain heaps of info which I hope will be of service.

tia

Please let me know if I can do anything further to assist.
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Well after a lot of trial and error i got your tiles to display.

I had to abandon a custom XYTileSource.
OSMDroid still requires that your tiles be named using the Slippy map convention.
That applies to offline tiles, it though i could workaround that but i couldn't - so your tiles MUST be renamed...

I found a rather simple way to do that automatically!

I have the latest version of MOBAC installed.
(I wondered if you'd found an old version of MOBAC to download the Google tiles?)
MOBAC supports adding SimpleCustomMapSource and FileBasedMapSource - you can add online tile sources and file based tile sources and MOBAC will pack the added tile source for you automatically naming them with the Slippy map convention.

The FileBasedMapSource sounded just what was required BUT again requires that the file based tiles be (already) named with Slippy map convention.

So the solution was to add a SimpleCustomMapSource.
I created an XML file and added it to the MOBAC mapsources folder:

B4X:
<?xml version="1.0" encoding="UTF-8"?>
<customMapSource>
   <name>BarryTiles</name>
   <minZoom>17</minZoom>
   <maxZoom>17</maxZoom>
   <tileType>png</tileType>
   <tileUpdate>None</tileUpdate>
   <url>http://localhost/android.martinpearman.co.uk/b4a/barry_tiles/gm_{$x}_{$y}_{$z}.png</url>
   <backgroundColor>#000000</backgroundColor>
</customMapSource>

I have Apache web server installed on my PC and transferred your tiles to the folder barry_tiles.
Started MOBAC and selected your tiles as source, copied the min and max latitude and longitude from the log in your previous post and created an offline tile source!
(Some tiles were missing but the process does work if you have all tiles for the selected area).

An example B4A Activity:

B4X:
Sub Process_Globals
   Dim MapCenter As GeoPoint
   Dim TileSource As String
   Dim ZoomLevel As Int
End Sub

Sub Globals
   Dim MapView1 As MapView
      Dim NewTileSourceName As String
   Dim TileSourceSpinner As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
   MapView1.Initialize("")
   
   If FirstTime Then
      MapCenter.Initialize(-37.85, 145.06)
      ZoomLevel=17
      
      Dim OfflineTileCacheFilename, TileCacheDir As String
      OfflineTileCacheFilename="barry_offline_tile_cache.zip"
      TileCacheDir=File.DirRootExternal&"/osmdroid"
      '   check if the offline tile cache has already been copied to the OSMDroid cache folder
      If File.Exists(TileCacheDir, OfflineTileCacheFilename)=False Then
         '   create the 'osmdroid' cache folder if it does not exist
         If File.Exists(TileCacheDir&"/", "")=False Then
            File.MakeDir(File.DirRootExternal, "osmdroid")
         End If
         '   copy the offline tile cache to the OSMDroid cache folder
         File.Copy(File.DirAssets, OfflineTileCacheFilename, TileCacheDir, OfflineTileCacheFilename)
      End If
      
      NewTileSourceName="BarryTiles"
      
      Dim CurrentTilesSources As List
      CurrentTilesSources=MapView1.GetTileSources
      If CurrentTilesSources.IndexOf(NewTileSourceName)=-1 Then
      '   the NewTileSourceName has not yet been added to the MapView
         Dim MyXYTileSource As XYTileSource
         
         MyXYTileSource.initialize(NewTileSourceName, 17, 17, 256, ".png", "http://localhost/")
         MapView1.AddXYTileSource(MyXYTileSource)
         
         '   note that after Activity_Pause (orientation change for example) the added XYTileSource will still exist in the MapView
         '   the added XYTileSorce will exist until the activity process is destroyed
         '   trying to add an XYTileSource more than once will not cause problems however - the AddXYTileSource method ensures that the tile source is only added once
      End If
      
      '   set the default initial TileSource
      TileSource=NewTileSourceName
   End If
   
   TileSourceSpinner.Initialize("TileSourceSelect")
   Activity.AddView(TileSourceSpinner, 0, 0, 100%x, 48dip)
   
   TileSourceSpinner.AddAll(MapView1.GetTileSources)
   TileSourceSpinner.Prompt="Select a TileSource"
   TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(TileSource)
   '   manually call the Spinner ItemClick Sub to sync the MapView TileSource with the spinner SelectedIndex
   TileSourceSelect_ItemClick(TileSourceSpinner.SelectedIndex, TileSourceSpinner.SelectedItem)
   
   MapView1.SetMultiTouchEnabled(True)
   MapView1.SetZoomEnabled(True)
   MapView1.Zoom=ZoomLevel
   MapView1.SetCenter3(MapCenter)
   Activity.AddView(MapView1, 0, 48dip, 100%x, 100%y-48dip)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   MapCenter=MapView1.GetCenter
   ZoomLevel=MapView1.Zoom
   
   '   save the currently selected MapView TileSource
   TileSource=MapView1.GetTileSource
End Sub

Sub TileSourceSelect_ItemClick (Position As Int, Value As Object)

   '   when first run this seems to prevent the offline tiles from loading
   '   rotate device and they appear...
   '   might be best to not bother disabling the data connection
   If Value=NewTileSourceName Then
      MapView1.SetDataConnectionEnabled(False)
   Else
      MapView1.SetDataConnectionEnabled(True)
   End If

   '   set the MapView TileSource
   MapView1.SetTileSource(Value)
End Sub

Disabling the data connection when your tiles are selected seems a bit unpredictable - when the Activity first runs no tiles are displayed, rotate the device and tiles appear.
So it might be best not to bother disabling the data connection - if your tiles are selected and you pan the map to an area where no offline tiles exist then OSMDroid will make tile requests to the device's local IP address.
No web server is likely to be running on the device so the requests will just fail but not use any network bandwidth.

Example project is attached but the archive of renamed tiles is too large to post so i'll send you a PM with a link to download it from.

Martin.
 

Attachments

  • barry_tiles_working.zip
    6.7 KB · Views: 197
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
You are a b4a, MOBAC, OSMDroid, Maping GOD!
I want to start a donation fund to have your clone created!
:icon_clap:


I used Easy GM DLr.

Thanks for the huge effort.
I'll have a look and see if I can reproduce the MOBAC maps myself.

I just happened to start looking at the MOBAC (Mobile Atlas Creator) this morning to see if I could DL my area again with a wider and deeper selection of cloudMade tiles. i.e. 0 - 18 Levels.
Ended up being 107,732 tiles of the melbourne area.
I accidently cancelled it somehow after an hour or so.
And havn't returned yet to see what the damage was.

I'm hoping to be able to dl tiles once then cashe them as you instruct.

Can't thank you enough!
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Thanks for the thanks!

Any tiles you've already downloaded with MOBAC will be cached on your hard drive so they won't be downloaded a second time if you try to again create an Atlas archive using those tiles.

If you want to do as i did and use MOBAC to package the G**gle tiles then you'll have to run a web server on your PC or upload the tile to some web space.
MOBAC can only access them with their original tile name if they being served by a web server.

XAMPP is a popular, quick and relatively easy way to get a working web server set up.
As well as an up to date version of Apache web server you'll also get up to date versions of PHP and MySQL installed - should you ever fancy trying a bit of web development.

Just be sure you read the documentation and secure your installation - otherwise you're opening a back door to all sorts of possible nasties on your PC.

Martin.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Thanks heaps for the suggestions.

I've got MS InetInfoServer 5.1 up n running on my home pc under winxp32.
Accessable via a dynamic domain name.

PHP, mySQL, MSAccess, Valentina Server, LC Server up n running successfully.

I tried apache but found out it was just another web server so dropped it.
Since I alread had IIS5.1 up n running successfully.

Just sitting down now to have a look for a step by step procedure for DLin GMs and converting with MOBAC.

The path can be a file path.
But the file path must be under the web server management as a virtual directory.
So the URL command can find it within the web server.
i.e. defined as an IIS virtual directory.
Right-click My Computer | manage | Services n Apps | IIS | Right-click web Sites | New Virtual Directory
But I'm too lazy.
M:/Inetpub/wwwroot is the IIS Web Site.
So c:/Barry_Tiles WILL NOT WORK unless its been defined as a Virtual Directory.


B4X:
<?xml version="1.0" encoding="UTF-8"?>
<customMapSource>
    <name>BGSTiles</name>
    <minZoom>18</minZoom>
    <maxZoom>18</maxZoom>
    <tileType>png</tileType>
    <tileUpdate>None</tileUpdate>
    <url>file:///M:/Inetpub/wwwroot/BGSTiles18/gm_{$x}_{$y}_{$z}.png</url>
    <backgroundColor>#000000</backgroundColor>
</customMapSource>


With MOBAC - if the maps are not displaying then the custom xml file hasn't been setup corrently.
i.e. the url is probably incorrect

Again with MOBAC the Zoom Levels with 18 ticked is showing 55 tiles
where there are actually 323 tiles as the source.
So I think the 55 Tiles are what MOBAC will be trying to create.

In MOBAC you can move the map around with the arrow keys.

SO you can start to lasso the top left tile,
and while the left mouse is still down lasso-ing
you can use the arrow keys to find the bottom right tile to select to finish the lasso with a left mouse up/release.

Then in MOBAC you create an atlas by clicking the "NEW" button and select OsmDroid ZIP as the output format.
And type in the name you want for your new atlas.

Then click "Add Selection" to add the selected tiles under your new atlas.
You can select more tiles and add selection those as well later if you want.

Then click "Setting" | Directories | Select - to point to the output folder to where you want to create the atlas in.
Then Click Create Atlas.
 
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Can't seem to get zoom 18 to work.
I've attempted about 300 different permutations a number of times to no avail.

Is there anything I need to do to the zome level 18 (attached) maps
before inlcuding them in the
barry_offline_tile_cache.zip
or to the BarryTileSource.b4a app?

The Run as Release didn't seem to copy the barry_offline_tile_cache.zip as expected.
So I started removing the barry_offline_tile_cache.zip from the sd card manually before Run as Release.


Other than:
B4X:
MyXYTileSource.initialize(NewTileSourceName, 17, 18, 256, ".png", "http://localhost/")
Tried and reTried about 300 different permutations.

Any suggestions would be greatly appreciated.

App will zoom the level 17 maps without changing to zoom level 18 maps.
Change orientations and app tries to to load zoom level 18 but will leave mapview blank.


----- *******
OK sorted.
I think you had hinted about an earlier version of MOBAC but I missed it.
Found an earlier version MOBAC v1.8
So much easier to use.

Level 18 shows address numbers
Level 19 would increase from 2k maps to 6kmaps.
So left 19 out.
But set the zoom to 0,19.
And app will zoom level 18 maps to level 19 zoom.
As in not load map 19 since it doesn't exist.
But zoom in on map level 18.
Perfect.

I thinks this might be where the Follow me/track my current position
might be getting lost/not centering map 18 when zoomed to 19.
More testing.

As in not load map 19 since it doesn't exist.
But zoom in on map level 18.

Very happy with with this so far.

Thanks again.
 
Last edited:
Upvote 0
Top