Android Question Google Maps API Key

Ajay Kakar

Member
Licensed User
Longtime User
Hi Friends,

I have a very unique situation. I have made an APP which displays the data for a dentist. The data is pulled in from a database sitting on a remote website. Everything works great. My plan is to make copies of the APP for each member and just insert the unique record locater in the APP. In this way, each APP shows the unique data of that particular member. Even this works great.

My problem is that one of the aspects is showing the Google map of the supplied address. To be able to do this, I had to register with Google Maps and I got an API key. I inserted this Key in the Application Manifest. When i made a copy of the original APP and compile it, the Google Maps shows a blank white screen. This indicates that the Key is a problem.

In the copy, I only change the Package name. I have to change this or else Google play store will not allow me to use an APK file with the same name for a second APP. So I have changed the name of the application file and have also changed the package name. I have not changed the application label and I have not even changed the keystore.

Of course I can easily generate an API Key for each of the copies, but I want to avoid this work if possible. Any suggestions.
 

Ajay Kakar

Member
Licensed User
Longtime User
Thanks for the tip. I was not aware of Maps V3. I will look into it right away. I assume I can plug into it from B4A.
 
Upvote 0

CidTek

Active Member
Licensed User
Longtime User
Correct me if I'm wrong but I think that v3 is a JavaScript based map. You can use it but it is quite different than the native GoogleMap.

Yes it is, but is also quite simple to learn as you basically are constructing an HTML file containing some mapping JS script and loading it into a Webview.
 
Upvote 0

CidTek

Active Member
Licensed User
Longtime User
Plus you can test it in any browser. I found my HTML editor (Homesite) an excellent tool as it also displays JS errors without jumping through hoops like I had to when debugging with the app and an emulator.
 
Upvote 0

Ajay Kakar

Member
Licensed User
Longtime User
Thanks CidTek. I did exactly the same. I got the source worked out (Javascript plus HTML) for it work on my browser. I have still not been able to figure out how to send the two parameters of the latitude and longitude to the HTML file. I am pretty good at ASP and HTML but the correct syntax for javascript is still a tough battle for me. Are you by any chance conversant with this. The piece of code is as follows

<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>

var map;
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}

google.maps.event.addDomListener(window, 'load', initialize(19,72));

</script>
</head>
<body>
<div id="map-canvas"></div>
</body>

I need to pass two parameters to this HTML file. The latitude and the longitude which will replace the two constants in the following code
center: new.google.mpas.latlng(-34.397, 150.664)

Just wondering if you would know the right syntax of getting the two variables with a request.querystring() call.

Ajay
 
Upvote 0

Ajay Kakar

Member
Licensed User
Longtime User
Hi CidTek,

Thanks to you I learnt that HTML code can be created in the APP and then displayed as Webview. It was indeed a new thing for me. I then tried to write a similar piece of code as you have written in HTML and Java to display an interactive google map. I tested the file and it works fine in my browser. When I copy it to my app the webview just appears as a white screen. I tried you example and it works fine. I dont see mine as very much different. The html string is as follows

htmlstring = "<!DOCTYPE html> <html> <head> <title>Simple markers</title> <style> html, body, #map-canvas { height: 100%; margin: 0px; padding: 0px } </style> "
htmlstring = htmlstring & " <script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script> <script> function initialize() { var myLatlng = new google.maps.LatLng(-25.363882,131.044922); "
htmlstring = htmlstring & " var mapOptions = { zoom: 4, center: myLatlng } ; var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); var marker = new google.maps.Marker({ position: myLatlng, Map: Map, title: '!' }); } "
htmlstring = htmlstring & " google.maps.event.addDomListener(window, 'load', initialize); </script> </head> <body onload='initialize()' > <div id='Map-Canvas'></div> </body> </html> "

I also tested with a simple "Hello World" HTML code and that worked. Do you think you can tell me whats wrong with the above code ?

Ajay
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…