Android Question Bluetooth gps with Google maps

kgf

Member
Licensed User
Hi I would like to add the ability to use an external gps with google maps in my app, without using 3rd party apps and mock location.
I am able to get the NMEA data from the bluetooth device but not sure of the best way to send it to Google maps location provider so that the map is using the external gps rather than the internal.

Do I need to parse the lat/long to a location or is there a way of injecting the nmea string to a 'LocationSource' or 'LocationManager' ?

Any suggestions on the best way to get the location from the bluetooth device as the location source for google maps

Thanks
 

drgottjr

Expert
Licensed User
Longtime User
are you seeing NMEA data like these?
$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68


you want the RMC NMEA string. it gives you the lat/lon in DMS (49 16.45 N lat/123 11.12W lat, 000.5 is speed). there are some simple conversion formulae around to convert those coordinates to those used by google maps, among others, (eg D + M/60 + S/3600). just feed the converted coordinates to your map app for positioning. don't forget to adjust the sign for N,W,S,E.
 
Last edited:
Upvote 0

kgf

Member
Licensed User
I am seeing the NMEA strings and have seen some code to parse them. But what I am not sure about is where to inject the location to google maps so that the blue dot shows the bluetooth position and I can use the location changed event.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
to integrate the bluetooth device with google maps, you need to
have a mock app declared in system settings. that will allow
you to use a location provider, but you lose fused location
provider, which means no built-in gps, no wifi, no cell, no other
google secret location data). of course, you'll also need the
mock app. since you say, no 3rd party apps, better get started
writing the mock app yourself.

i had assumed you were already communicating with the
device using a serial connection: once you had your nmea
data, you would parse them to derive lat/lon and add a marker to your map.
judging by your question, i now get the impression you don't know
how to add a marker, which leads me to believe you aren't
using the google maps library (yet), otherwise you would
surely know how to add a marker.

as to the change location event, it depends on how your mock app
works with google maps. you might have to implement a little something
yourself (eg, every 10 seconds compare current reading with last reading
and update map, if appropriate).
 
Upvote 0

kgf

Member
Licensed User
I am unsure by what you mean by my own mock app. I am trying to avoid a second app that needs system settings or developer options for mock location.

I have a working google map with polygons and markers, this has GoogleMap1.MyLocationEnabled = True which shows the blue dot on the map at the gps location.

What I would like to do is somehow inject the bluetooth gps position to a Location Source so that the map location is from the serial nmea data. While I could parse the lat long from the stream to create a marker, what I am trying to do is to get the blue dot to be the bluetooth gps position
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
in order to integrate an external gps device into google
maps, you need to use a "mock app" and to inform your
android device to use that app as a location provider.
either you understand this or you don't. repeating what you
want to do does not change what is required by google.

there is nothing stopping you from deriving lat/lon
coordinates from your bluetooth gps device. and there is
nothing stopping you from using those coordinates to
place a marker on a map.

if you want google maps to handle the readings from an
external gps, you need a mock app. without a mock app,
google maps will use its built-in providers. when you set
the mock app as your provider, google maps will use it and
turn off the built-in providers.

if you want to use the readings from your bluetooth gps,
but you do not use a mock app, then you will simply
process the readings yourself and place a marker that
corresponds to those readings on your map. if you want
to emulate a "location changed" event, you set a timer to
check current readings from the previous readings. it is
essentially the same thing google maps is doing, only more
efficiently.
 
Upvote 0

kgf

Member
Licensed User
Thanks for your reply, I was hoping there was a way to inject the coordinates into some kind of custom location source/provider for google maps but if it cant be done I will have to use a custom marker for current position
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Thanks for your reply, I was hoping there was a way to inject the coordinates into some kind of custom location source/provider for google maps but if it cant be done I will have to use a custom marker for current position
the "custom location source/provider for google maps" that you refer to is the mock app.
 
Upvote 0
Top