6 Replies - 14464 Views - Last Post: 27 December 2012 - 01:57 AM

#1 deucalion0   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 27-November 10

Help using the new Android Google map API V2

Posted 24 December 2012 - 02:21 PM

Hey guys, I am trying to build a brand new map application using the new maps API from Google, but I am struggling. I got my map set up with API key it all works, here is the only class I have so far:


package com.example.newmaps;


import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity  {

	
	  private GoogleMap mMap;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		 setUpMapIfNeeded();
	
	}

	  @Override
	    protected void onresume() {
	        super.onresume();
	        setUpMapIfNeeded();
	    }
	  
	  
	  
	  private void setUpMapIfNeeded() {
	        // Do a null check to confirm that we have not already instantiated the map.
	        if (mMap == null) {
	            // Try to obtain the map from the SupportMapFragment.
	            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
	                    .getMap();
	            // Check if we were successful in obtaining the map.
	            if (mMap != null) {
	                setUpMap();
	            }
	        }
	    }
	  
	  

	  
	  private void setUpMap() {

		      
		  
	    }
	}



I cannot figure out how to get the users location never mind try the advanced stuff I will need to do eventually, can anyone help me out?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Help using the new Android Google map API V2

#2 EndLessMind   User is offline

  • Android Expert
  • member icon

Reputation: 273
  • View blog
  • Posts: 1,252
  • Joined: 13-March 09

Re: Help using the new Android Google map API V2

Posted 24 December 2012 - 07:44 PM

Hi!
Have you looked at the Sample Code?

I can be found at this page
Was This Post Helpful? 2
  • +
  • -

#3 farrell2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: Help using the new Android Google map API V2

Posted 26 December 2012 - 12:14 PM

The LocationManager class has getLastKnownLocation() which will return a Location object with the users last known location. That's the easy part. The hard part is adding the location to an overlay and viewing it on a mapview. :) Actually, it's not that hard. You just need a tutorial. BY successfully getting your api key, you' have done the hardest part. Here's a simple example.
Was This Post Helpful? 1
  • +
  • -

#4 deucalion0   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 27-November 10

Re: Help using the new Android Google map API V2

Posted 26 December 2012 - 12:23 PM

Hey guys, Endlessmind, I tried for hours to get those code samples to work, and even going through the code I could not figure out which part was getting the users location. The new API is confusing to me.

Farrell2K, I had a look at the example you posted, is this code for the V2 API? That is my problem, I am unsure which code is which now, the example you posted was for using the V1 API, does V2 support all this code? Looking through some other V2 samples, it looks totally different, I just cannot figure out what is the code I need. I want to start simple, get the map on screen, simple, get the location, sot so simple. I can get the get location button to show on the top right corner of the map but tapping it does nothing.

Does anyone know, if the map shows on screen then the API key is working, correct?

Many thanks guys!!
Was This Post Helpful? 0
  • +
  • -

#5 EndLessMind   User is offline

  • Android Expert
  • member icon

Reputation: 273
  • View blog
  • Posts: 1,252
  • Joined: 13-March 09

Re: Help using the new Android Google map API V2

Posted 26 December 2012 - 02:27 PM

Okay. I've looked at the code and documents a bit now, and i think i've figured out.
First, get the location from the GPS as shown here

Then look ad the code-block at the bottom of this page
I'll get the location from the LocationManager, and then inputing it to the GoogleMap my using moveCamera(CameraUpdateFactory.newLatLngZoom(LatLgn coordinates, int zoom));

Hope this helps
Was This Post Helpful? 1
  • +
  • -

#6 deucalion0   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 27-November 10

Re: Help using the new Android Google map API V2

Posted 26 December 2012 - 03:33 PM

Cheers endless mind, I will look into that now! :)

Does anyone know if with the new API that searching places is possible?


Cheers!!
Was This Post Helpful? 0
  • +
  • -

#7 farrell2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: Help using the new Android Google map API V2

Posted 27 December 2012 - 01:57 AM

View Postdeucalion0, on 26 December 2012 - 07:23 PM, said:

Farrell2K, I had a look at the example you posted, is this code for the V2 API? That is my problem, I am unsure which code is which now, the example you posted was for using the V1 API, does V2 support all this code? Looking through some other V2 samples, it looks totally different, I just cannot figure out what is the code I need. I want to start simple, get the map on screen, simple, get the location, sot so simple.


The V1 examples using MapView will work fine with the V2 api. The V2 api is of course just newer functionality and support for things like Fragments.

The example I posted is simple one that displays your location on a map. Learn the basics, first. If you want to keep going with more advanced stuff, go ahead.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1