i have a place coordinate, i mean altitude and longitude , and i want to show this place with google map in android application, so how can i use this altitude and longitude to pass in a function and show that place in the app, i don't need to show current place , i have this longitudes and altitudes from before,and i save theme as a string in my application , is there any function or layout to show this place with this coordinates in application ? or i have to use some different method to show this places on map?
private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Hello world"));
You could try:
String urlAddress = "http://maps.google.com/maps?q="+ lattitude string +"," + longitude_string +"("+ "Hello location" + ")&iwloc=A&hl=es";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
startActivity(intent);
This will open google maps with whatever coordinates you provide.
Related
I have followed a 24 hours textbook and created an Android app that is supposed to launch Google maps and navigate to a specific location based on latitude and longitude coordinates hard coded into the app. However, when I launch the app and run the code it opens Google maps or Google Earth and always defaults to my current location. How do I prevent it from doing this?
I am trying to get my app to go to a specific latitude and longitude, but when it launches Google Maps or Google Earth it always defaults to my current location. Java Code is as follows:
Button mapButton = (Button) findViewById(R.id.button2);
mapButton.setOnClickListener(new View.OnClickListener() {
#override
public void onClick(View view) {
String geoURI = "geo:37.422,-122.0847z=23";
Uri geo = Uri.parse(geoURI);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, geo);
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
How do I get it to override the default location and go to the coordinates I have hard coded above?
Looking at the documentation, the line:
String geoURI = "geo:37.422,-122.0847z=23";
Appears to be invalid syntax, but might be wanting to zoom. Try:
String geoURI = "geo:37.422,-122.0847?z=23";
Zoom level only goes up to 21, however, so also try:
String geoURI = "geo:37.422,-122.0847?z=21";
If neither work, use a basic string without any zoom:
String geoURI = "geo:37.422,-122.0847";
Try this:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
You can omit (Label+Name) if you don't want a label, and it will choose one randomly based on the nearest street or other thing it thinks relevant.
You can create LatLng object and tell google map to load the location. Code to do that will be something like this:
double lat=26.52719;
double lng=88.72448;
LatLng myLocation = new LatLng(lat,lng);
if(this.googleMap !=null){
this.googleMap.addMarker(new MarkerOptions().position(myLocation).title("Your current Location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
this.googleMap.moveCamera(CameraUpdateFactory.newLatLng(myLocation));
}
Remember you should apply this in onMapReady callback and to turn off your current location placing in google map you can do
this.googleMap.setMyLocationEnabled(true);
Had an issue where I needed to place a marker at the exact centre of my map screen and looked at a lot of questions and answers that were not exactly what I wanted to do. The app allows the user to move map about and then once crosshairs that are exactly in the centre of the map are at the desired location, you tap a button and a marker appears at that location.
map.getProjection().fromScreenLocation almost met my needs but I did not have the coordinates so could not implement that solution.
So my answer hopefully will help someone in the same situation.
So my soltuion was to use the getCameraPosition method as follows. And its fired from the button R.id.addMarker in my xml.
findViewById(R.id.addMarker).setOnClickListener(
new View.OnClickListener(){
#Override
public void onClick(View view) {
if(myMap != null){
double myLat = myMap.getCameraPosition().target.latitude;
double myLng = myMap.getCameraPosition().target.longitude;
LatLng markerPoint = new LatLng(myLat, myLng);
myMap.addMarker(new MarkerOptions().position(markerPoint)).setTitle("next marker");
}
}
}
);
Hope it helps someone in the same predicament.
I don't understand why fromScreenLocation doesn't suit your needs...
If you pass the map's width and the map's height divided by two as it's parameters, this function will return you a LatLng object giving you the corresponding location in terms of latitude and longitude. After that, it is easy to place a Markerat this position.
Hi I wanted to know how I can slowly zoom in on a marker in a map activity in android. Currently my app just opens zoomed in on the marker. I would like it to zoom in slowly when the app is opened.
This is my current code
LatLng mark = new LatLng(21.197384, 6.369441);
mMap.addMarker(new MarkerOptions().position(mark).title("Marker for Mark"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
Use mMap.animateCamera instead of mMap.moveCamera
Also, you can control the duration of the movement using
animateCamera (CameraUpdate update, int durationMs, GoogleMap.CancelableCallback callback)
In your example, change
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
for
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
or, if you want the movement to last 200ms:
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel), 200, null);
Try mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel)); instead of
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
In this way you can achieve this --
CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(latitude_origin, longitude_origin));
CameraUpdate zoom = CameraUpdateFactory.newLatLngZoom(new LatLng(latitude_origin, longitude_origin),3);
googleMap.animateCamera(center);
googleMap.animateCamera(zoom);
Hope this helps!
I working with google maps in Android. I am stuck with adjusting zoom level.
I have one marker in center of map that i set by using mapController.setCenter(current_location);
And I have 10 or more marker showing in map with different color.
Expected Result: current location of person should in center always and I have to adjust a zoom level so that green marker will show in screen( Current location marker in center).
What I tried:
int greenlat = (int) (AppCoordinates.getInstance().latitudelist.get(0) * 1E6);
int greenlong = (int) (AppCoordinates.getInstance().longitudelist.get(0) * 1E6);
int currentlat = (int) (AppCoordinates.getInstance().getCurrentLatitude() * 1E6);
int currentlong = (int) (AppCoordinates.getInstance().getCurrentLongitude() * 1E6);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mapController.zoomToSpan((int) (Math.abs(greenlat - currentlat) * 1), (int)(Math.abs(greenlong - currentlong) * 1));// to have some padding on the edges.
mapController.animateTo(new GeoPoint((greenlat + currentlat), (greenlong + currentlong)/2));
With is I am able to show booth the markers in screen, but I want cureent location to be shown in center of screen.
My idea is to manipulate LatLngBounds since its representing all included markers to be viewed in aligned rectangle on the map. So we just need to recognise all points that make current location will be viewed at the center of map.
Put all markers into the bound.
Move camera to your current location as center point.
Get 4 locations of all corners of the current map and put it together in list of point in the bound.
this is my sample:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
Marker myLocation = mMap.addMarker(new MarkerOptions()
.position(new LatLng(2.6,101.5))
.title("My-Current-Location"));
Marker addMarker1 = mMap.addMarker(new MarkerOptions()
.position(new LatLng(2.6,101))
.title("Hello world-1"));
Marker addMarker2 = mMap.addMarker(new MarkerOptions()
.position(new LatLng(2.7,101))
.title("Hello world-2"));
Marker addMarker3 = mMap.addMarker(new MarkerOptions()
.position(new LatLng(3.7,105))
.title("Hello world-3"));
builder.include(myLocation.getPosition());
builder.include(addMarker1.getPosition());
builder.include(addMarker2.getPosition());
builder.include(addMarker3.getPosition());
//haha enough to use for loop for all your markers
int padding = 100; // offset from edges of the map in pixels
CameraUpdate cameraUpdate =CameraUpdateFactory.newLatLngBounds(builder.build(), padding);
mMap.moveCamera(cameraUpdate);
mMap.moveCamera(CameraUpdateFactory.newLatLng(myLocation.getPosition()));
LatLng nrLatLng = mMap.getProjection().getVisibleRegion().nearRight;
LatLng frLatLng = mMap.getProjection().getVisibleRegion().farRight;
LatLng nlLatLng = mMap.getProjection().getVisibleRegion().nearLeft;
LatLng flLatLng = mMap.getProjection().getVisibleRegion().farLeft;
builder.include(nrLatLng);
builder.include(frLatLng);
builder.include(nlLatLng);
builder.include(flLatLng);
cameraUpdate =CameraUpdateFactory.newLatLngBounds(builder.build(), padding);
mMap.animateCamera(cameraUpdate);
After starting new project, i've faced a problem with zooming maps in google maps v2 in android. I can't zoom map using default controls. The following code shows Camera position changing
CameraPosition currentPlace = new CameraPosition.Builder()
.target(mMarker.getPosition())
.bearing(bearing)
.zoom(14f) //apply zoom here
.build();
map.moveCamera(CameraUpdateFactory.newCameraPosition(currentPlace));
After this function i cannot zoom map with default controls
The solution to this problem is that we should use markers zoom when we move camera :
CameraPosition currentPlace = new CameraPosition.Builder()
.target(mMarker.getPosition()).bearing(bearing)
.zoom(map.getCameraPosition().zoom)
.build();
map.moveCamera(CameraUpdateFactory.newCameraPosition(currentPlace));
Try this,
get the location longitude and latitude
static LatLng loc1 = new LatLng(6.9009960, 79.8548823);
//zoom the location
map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc1, 15));