I am using Google Map API v2
in my application to show Maps.
I have followed all the steps, that is to be followed to enable Google Map in my application.
public class PinLocationOnMapView extends FragmentActivity {
private double mLatitude = 0.0, mLongitude = 0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = SupportMapFragment.newInstance();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
}
}
If I use this code, it shows me map, but if I provide my latitude/longitude values, map tiles does not load, and I see only white tiles.
Following is the code written in onCreate() of above class:
if (getIntent().getExtras() != null) {
final Bundle bundle = getIntent().getBundleExtra("LOCATION");
mLatitude = bundle.getDouble("LATITUDE");
mLongitude = bundle.getDouble("LONGITUDE");
} else {
finish();
}
GoogleMapOptions options = new GoogleMapOptions();
LatLng latLng = new LatLng(mLatitude, mLongitude);
CameraPosition cameraPosition;// = new CameraPosition(latLng, 0, 0, 0);
cameraPosition = CameraPosition.fromLatLngZoom(latLng, (float) 14.0);
options.mapType(GoogleMap.MAP_TYPE_SATELLITE).camera(cameraPosition)
.zoomControlsEnabled(true).zoomGesturesEnabled(true);
SupportMapFragment fragment = SupportMapFragment.newInstance(options);
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
Also, I have a list of lat/long values. I want to show them on MapFragment
, how to show multiple markers on MapFragment
?
I tried with MapView
and ItemizedOverlay
, but it didn't work for me. I believe I have correctly created the SHA1
key to get the API
key, because if that was wrong, I could not see map using MapFragment
as well, but I can see that if I don't pass the lat/log value.
To add multiple markers to map while converting address (ie. 123 Testing Street Lodi ca) to LatLng using geoCoder, the example code below will work.
I do it like this to show car positions on the map with markers of different colors:
Cars is an
ArrayList
of custom objects and mMarkers is anArrayList
of markers.Note : You can show map in fragment like this:
And just call
setUpMapIfNeeded()
inonCreate()
Try this code which calls to an xml file in you web site root directory -
One way to add markers is by loading an xml file that resides on the root directory(see code below), which contains the marker html.
The code here sets up map space and a side-bar column to hold the map and links for the markers. Note that both a div tag with an id and a side-bar td id for the html and map items.
You can set up the markers, but note the need to use special characters that must be tagged correctly; for example ampersand (&) should actually be coded as "&" + "amp" + ";" (without quotes). The same applies to greater than and less than characters, and so on. It is a chore if you have several markers, but once in place it's easy to change as it doesn't require any assemblies needing to be built or coding inside the app. In the script which reads the file, using the CDATA tag technically should make the use of special character representation unnecessary, but for Gmaps API v2, I use them anyway. For my example the xml file name is example3.xml.
You can format the xml like this:
// ]]>
I don't know maybe u fixed the code and now it's ok, but in the
onCreate()
the second
mLatitude
I think it has to bemLongitude
just like u call it in the next rows.Sorry if I'm late with the answer and is useless.
first craete Method setupDestationLocation
Now Just call in method inside method (onMapReady)
You could try this: