Launch google maps after clicking Marked - android

I have got the following code, and what I want to do is to open "Google Maps" APP [How to go] to the marker I have set up:
// S E T M A P P O I N T
mLocationClient = new LocationClient(this, this, this);
mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
map = mapFragment.getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.getUiSettings().setZoomControlsEnabled(true);
map.getUiSettings().setCompassEnabled(true);
map.setOnMapClickListener(this);
map.setMyLocationEnabled(true);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), ZOOM));
map.clear();
addressText = GetGeolocation.getgeocoder(Date_Accept.this, latitude, longitude);
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(addressText)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
marker.showInfoWindow();
How can I open "Google Maps" app to get the route to that point?

you should be able to fire an intent with the maps url and let android handle it for you
read about that here

Related

Look if current location is near marker

I have a Google Maps API Activity and want the markes only to be clickable if the user is in a certain radius to them.
How is the best way to do this?
This is how I set my markers:
Marker marker1 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.793012, 9.926201))
.title(getString(R.string.Title1))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Marker marker2 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.792742, 9.939118))
.title(getString(R.string.Title2))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Marker marker3 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.793349, 9.932558))
.title(getString(R.string.Title3))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Solution code:
LatLng markerPosition = marker.getPosition();
myLocation = locationManager.getLastKnownLocation(provider);
Location markerLoc = new Location("marker");
markerLoc.setLatitude(markerPosition.latitude);
markerLoc.setLongitude(markerPosition.longitude);
float meters = myLocation.distanceTo(markerLoc);
You can get the LatLng of the markers by marker.getPosition(); then you can compare it with the CurrentLocation. To do this, you can check this post, and next you can make clickable or notclickable a marker as follows:
getMap().setOnMarkerClickListener(new OnMarkerClickListener() {
public boolean onMarkerClick(Marker marker) {
onMapClick(marker.getPosition());
return true;
}
});
If you return true for the function, it means that you've accepted the occurred click event on your marker; otherwise, you've not accepted it.
Moreover, you can do it with:
MarkerOptions.clickable and Marker.setClickable.
This is just a guide who how I would do what you want. hope it helps. :)

Android Google Maps - remove location accuracy circle

I'm displaying a Google map (v2 API) in an Android app like so:
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
Requesting location:
mLocationClient = new LocationClient(getApplicationContext(), this, this);
mLocationClient.connect();
What I want to do is show just the marker for the current location, and not the circle indicating location accuracy. I've looked through the documentation and API reference, and searched around and haven't found an option to turn that off.
The blue circle on the map is enabled eith the following line:
map.setMyLocationEnabled(true);
You only have to set it to false and it will disappear:
map.setMyLocationEnabled(false);
To draw your marker you need to get the users location using a listener. You can do something like this:
GoogleMap.OnMyLocationChangeListener locationListener = new GoogleMap.OnMyLocationChangeListener() {
#Override
public void onMyLocationChange(Location location) {
drawMarker(location);
private void drawMarker(Location location) {
LatLng currentPosition = new LatLng(location.getLatitude(),
location.getLongitude());
map.addMarker(new MarkerOptions()
.position(currentPosition)
.snippet(
"Lat:" + location.getLatitude() + "Lng:"
+ location.getLongitude())
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.title("position"));
}
};
map.setOnMyLocationChangeListener(locationListener);
You can also use your LocationClient and do the same if you need to.
I got rid of that annoying circle like this:
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker").snippet("Snippet").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));

My App not loading Google map

I am using this code for load google map
private GoogleMap myMap;
if(myMap!=null){
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
marker = myMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(getAddress(latitude, longitude)));
Location = new LatLng(latitude, longitude);
CameraPosition cameraPosition = new CameraPosition.Builder().target(Location).zoom(15)
.bearing(90) // Sets the orientation of the camera to
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
// myMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 15));
}
but map is not loading and occurring this issue
You must install the latest Google play services in your phone/tab/emulator before running the app.
For google play on emulator.

Google map v2 marker not starting with my location

SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(true);
Marker marker = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(location.getLatitude(),location.getLongitude()))
.title("Me")
.snippet("Population: 776733"));
When I run the code,google map is supposed to show the place where I am with the marker,but the map is opening up with some other place,no my current location,and I have to move to my location manually to find the marker.
You should animateCamera on that particular location Marker like
LatLng current_loc= new LatLng(lat, lng);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(current_loc, 18.0f));
For more information go to https://developers.google.com/maps/documentation/android/views#moving_the_camera
try this,
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(your latitude, you longitude)));

How to add multiple marker and overlay in v2 google map?

I am using google map v2 api. In that i need to show multiple markers and multiple overlays. I don't have any idea about this. If anybody knows answer kindly share your thoughts. Thank you.
For single marker and overlay i use this code
hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
Use like this
LatLng one = new LatLng(2.40744, 77.014702);//Latitude and long points
LatLng two = new LatLng(2.407440, 77.014702);
LatLng three = new LatLng(2.4013, 76.951340000000002);
.......
Similarly u can use more lat and long
myMarkerOne = gm.addMarker(new MarkerOptions()
.position(one)//use LatLng obj
.title("C")
.snippet("dsfd")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
myMarkerTwo = gm.addMarker(new MarkerOptions()
.position(two)
.title("C")
.snippet("dsfds")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
myMarkerThree = gm.addMarker(new MarkerOptions()
.position(three)
.title("A")
.snippet("dfd")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
and so on..
Try this one.It will be better
String values[]={"2.40744, 77.014702","6.407440, 77.014702","10.4013, 76.951340000000002"};
GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment supportMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
// Getting a reference to the map
googleMap = supportMapFragment.getMap();
for(int i=0;i<values.length;i++)
{
String s[] = values[i].split(",");
String v1 = s[0];
String v2 = s[1];
googleMap.addMarker(new MarkerOptions()
.position(
new LatLng(Double.valueOf(v1),Double.valueOf(v2)))
.title("Hi")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
}
}

Categories

Resources