Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 6    Views: 218

miku
Aspiring developer
Profile
Posts: 405
Reg: Feb 20, 2014
zagorje ob savi
10,600
12/17/15 04:45 AM (8 years ago)

Android Studio and Google Maps Android API

I followed this manuals: https://developers.google.com/maps/documentation/android-api/start?hl=en 1. I put API key into google_maps_api.xml: <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false"> AI…………as </string> 2. res/layout/activity_maps.xml contains code: <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.dolina.MapsActivity" /> 3. MapsActivity.java contains: package com.dolina; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in Sydney and move the camera LatLng sydney = new LatLng(-34, 151); mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); } } Did I miss something that my Google Map doesn’t work?
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
12/17/15 10:27 AM (8 years ago)
Hi @miku, Are you testing this on an emulator? Because they simply don't work in that environment...it has to be tested on a real device. Mark
 
Caslor
Android Fan
Profile
Posts: 191
Reg: Jul 26, 2013
athens
1,910
like
12/17/15 01:32 PM (8 years ago)
1) first you need the api key 2) then you need the SHA1 from the signature you will use for your apk 3) you register the api key in the google developer console with the SHA1 and the name of your apk ''com.etc'' 4) you place the google API key in the AndroidManifest.xml 5) you compile the apk with the signature you use for the sha1 you will have the maps (you have to test is in a real device... not in emulator )
 
miku
Aspiring developer
Profile
Posts: 405
Reg: Feb 20, 2014
zagorje ob savi
10,600
like
12/17/15 01:34 PM (8 years ago)
No, on different devices with different Android versions. I asked similar question few times, but never got answer to my question: how to add Google Map to Android Studio and that it really works. Of course I have good API key which works on Eclipse.
 
Caslor
Android Fan
Profile
Posts: 191
Reg: Jul 26, 2013
athens
1,910
like
12/17/15 01:49 PM (8 years ago)
as i told.. if you are making a new app... you have to add the the name of the app to the google developere consol for the apis you can have more than one app connected / registered to the api key.. if you use for all of them the same signature... then you have to add the name only and copy the SHA1 from the other apps then you just have to place the api key in the AndroidManifest.xml and not to the ''google_maps_api.xml'' build your apk with the signature you used for SHA1 and then install the apk to a real device..
 
miku
Aspiring developer
Profile
Posts: 405
Reg: Feb 20, 2014
zagorje ob savi
10,600
like
12/18/15 12:43 AM (8 years ago)
Thanks Caslor, my API key has correct SHA1, is it possible that your solution is only for BT server and AS package, but not self-hosted? My app is self-hosted and if I enter API key in manifest it doesn't work.
 
Caslor
Android Fan
Profile
Posts: 191
Reg: Jul 26, 2013
athens
1,910
like
12/18/15 04:47 AM (8 years ago)
No, i use also selfhosted so something else is wrong ...
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.