Reputation: 2440
I have a lot to do before I am finished, after 8 hours straight working on this I need to ask for help. I have managed to set up V2 maps on Android they work on my device, I do not know where to find a resource that could help me build this up to a more advanced map application, I cannot even get the users location to show. I am debugging on an Android phone which has the internet. I have read more than 10 questions on Stack overflow as well as read through some of the documentation on Google.
Here is my class so far:
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
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() {
mMap.setMyLocationEnabled(true);
mMap.getMyLocation();
}
}
I need to build up to getting the users location, then allowing the user to search for places and store them, does anyone think this would be possible in V2 maps?
Many thanks!
Upvotes: 3
Views: 6392
Reputation: 697
And it has. See the Location API for Google Maps V2. http://developer.android.com/training/location/index.html
Upvotes: 1
Reputation: 766
Today I received an e-mail from Google Maps, which is referred to get the current location on the new Google Maps API v2,
Since last month, many developers, including me, have found a problem or inconvenience of getting the current location on new Google Maps API v2.
That problem is
" Use a GoogleMap and enable my location using setMyLocationEnabled(true). There is no way (I mean no proper way as there is no callbacks) to be notified of a location change using the default/built-in LocationSource. There should be a way to be notified of a change in the user/my location. API v1 had a way to do it. No having it requires building a complex algorithm that may not be in sync with what the GoogleMap is currently displaying."
The above question is linked at here. http://code.google.com/p/gmaps-api-issues/issues/detail?id=4644
Then today Google maps team sent an e-mail to many developers:
"This issue will be fixed in the next release of the Maps Android API."
That's it all..
Upvotes: 1
Reputation: 1006614
I need to build up to getting the users location, then allowing the user to search for places and store them, does anyone think this would be possible in V2 maps?
You would need to find the user's location via LocationManager
, as you would in any Android app. Optionally, you can feed those locations to Maps V2 via calling setLocationSource()
on your GoogleMap
.
UPDATE
If you use setMyLocationEnabled(true)
on GoogleMap
, you can retrieve a location via getMyLocation()
on GoogleMap
. This is simpler than rolling your own location tracking, but you do not get as much control (e.g., you are not informed of movement).
Upvotes: 7