Android Maps KML Handler - android

Ok so at the moment I'm getting a null pointer exception when adding to the list of overlays. I've declared this at the top of the map activity class:
private static List<Overlay> mOverlays;
And then further down I've got this for my source/ from point:
Drawable fromDrawable = getResources().getDrawable(R.drawable.pin_blue);
OverlayItem fromOverlayItem = new OverlayItem(fromGeoPoint, "Hello!", "This is your current Location.");
MapWhatsNearOverlay fromItemizedOverlay = new MapWhatsNearOverlay(fromDrawable);
mOverlays.add(fromItemizedOverlay);
connectAsyncTask _connectAsyncTask = new connectAsyncTask();
_connectAsyncTask.execute();
mMapView.getOverlays().add((Overlay) mOverlays);
And the same for the destination as well, but the null pointer exception pops up when processing the bottom line of code.

Refer this link to draw driving path in your application. You just need to add the four classes present in the link in your project and call the below lines when you need to display the route.
SharedData data = SharedData.getInstance();
data.setAPIKEY("0RUTLH7cqd6yrZ0FdS0NfQMO3lioiCbnH-BpNQQ");//set your map key here
data.setSrc_lat(17);//set your src lat
data.setSrc_lng(78);//set your src lng
data.setDest_lat(18);//set your dest lat
data.setDest_lng(77);//set your dest lng
startActivity(new Intent(YourActivity.this,RoutePath.class));//add RoutePath in your manifeast file
//Also add the permission to your manifeast file

Related

Get placemark from getPlacemarks with Google Maps Android API utility library

I'm using this library to show a kml markers in a map in Android Maps V2.
I´m trying to get the lat and lon from a kml layer to do zoom directly to a placemark after add it to a map.
I tried to do this:
layer = new KmlLayer(mMap,R.raw.ruta, this );
layer.addLayerToMap();
for (KmlPlacemark act : layer.getPlacemarks()){
System.out.println("hi");//not iterate
}
but it doesn´t enter in the loop I read this kml-feature but don't work as is
You will have to read the 1st container of the KML-layer before attempting to read information about the placemarks:
KmlContainer = layer.getContainers().iterator().next();
if (kmlContainer == null) return;
for (KmlPlacemarks placemark : kmlContainer.getPlacemarks()) {
// Do the placemark magic here!
}

Nutiteq Android- Offline map is not displaying

Here is my code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setComponents(new Components());
RasterDataSource datasource = new PackagedRasterDataSource(new EPSG3857(), 11, 12, "t{zoom}_{x}_{y}", getApplicationContext());
RasterLayer mapLayer = new RasterLayer(datasource, 16);
mapView.getLayers().setBaseLayer(mapLayer);
mapView.setFocusPoint(mapView.getLayers().getBaseLayer().getProjection().fromWgs84(217884.21f, 1928068.13f));
//mapView.setZoom(15);
}
I have added .map file from http://www.mapcacher.com/ and converted it to PNG using http://dev.nutiteq.ee/jarmaps/ . I have mentioned the correct zoom level, checked that t11 and t12 files exist under res/raw. Also I have converted lat/lon to the required format using http://www.latlong.net/lat-long-utm.html . What is it that I am doing wrong.I don't get any errors in log cat but a blank page with Nutiteq logo is diplayed.
This line is wrong, instead of UTM coordinates
mapView.setFocusPoint(mapView.getLayers().getBaseLayer().getProjection().fromWgs84(217884.21f, 1928068.13f));
you should use WGS84, lat-long coordinates (first parameter long as x, then lat as y), like method name fromWgs84 suggests. No need to convert from/to UTM externally.

Tool to draw polygon on google map by passing coordinates

I am doing android app for field drawing and now I am making share function. Is there are any way to pass field coordinates from mobile to maps.google.com, make link, and send this link for example to friend via sms or email, that he just need to push the link and my drawed field will show up to him in browser? Is there any tool to do this or I need to create some web app for this?
Try out it
// To draw boundray on map
private void drawPolygon() {
polygonOptions = new PolygonOptions(); // consider new options
setStrokeWidth();
for (LatLng latLng : drawCoordinates) {
Marker marker = googleMap.addMarker(new MarkerOptions().position(latLng).title(latLng.toString()));
marker.setVisible(false);
polygonOptions.add(marker.getPosition()).strokeColor(Color.RED);
polygonOptions.fillColor(Color.TRANSPARENT);
polygonOptions.visible(true);
}
List<LatLng> points = polygonOptions.getPoints();
if (!points.isEmpty()) {
polygon = googleMap.addPolygon(polygonOptions);
Log.i("Poly lines","Successfully added polyline on map");
}
}

The source attachment does not contain the source for the file Layoutinflater.class

I'm trying to write an android application that uses google maps api version 2.
In Debug the application crashes when it executes the instruction:
setContentView(R.layout.activity_poi_map);
This is the error:
the source attachment does not contain the source for the file
Layoutinflater.class
I don't understand the reason. In headers I imported the whole class
android.view.*
Thank you in advance for any answer.
This is the code:
public class PoiMap extends FragmentActivity {
private GoogleMap pMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent callerIntent = getIntent();
final LatLng userCoord = callerIntent.getParcelableExtra("userCoord");
final Poi poi = (Poi) callerIntent.getSerializableExtra("poi");
setContentView(R.layout.activity_poi_map);
setUpMapIfNeeded(userCoord);
// Sets a callback that's invoked when the camera changes.
pMap.setOnCameraChangeListener(new OnCameraChangeListener() {
#Override
/* Only use the simpler method newLatLngBounds(boundary, padding) to generate
* a CameraUpdate if it is going to be used to move the camera *after* the map
* has undergone layout. During layout, the API calculates the display boundaries
* of the map which are needed to correctly project the bounding box.
* In comparison, you can use the CameraUpdate returned by the more complex method
* newLatLngBounds(boundary, width, height, padding) at any time, even before the
* map has undergone layout, because the API calculates the display boundaries
* from the arguments that you pass.
* #see com.google.android.gms.maps.GoogleMap.OnCameraChangeListener#onCameraChange(com.google.android.gms.maps.model.CameraPosition)
*/
public void onCameraChange(CameraPosition arg0) {
// Move camera.
if (poi != null){
LatLng poiCoord = poi.getLatLng();
pMap.addMarker(new MarkerOptions()
.position(poiCoord)
.title(poi.getName())
.snippet(poi.getCategory())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_star)));
Log.d("userCoord", userCoord.toString());
Log.d("poiCoord", poiCoord.toString());
double minY = Math.min(userCoord.latitude, poiCoord.latitude);
double minX = Math.min(userCoord.longitude, poiCoord.longitude);
double maxY = Math.max(userCoord.latitude, poiCoord.latitude);
double maxX = Math.max(userCoord.longitude, poiCoord.longitude);
Log.d("minY", " " + minY);
Log.d("minX", " " + minX);
Log.d("maxY", " " + maxY);
Log.d("maxX", " " + maxX);
LatLng northEast = new LatLng(maxY, maxX);
LatLng southWest = new LatLng(minY, minX);
LatLngBounds bounds = new LatLngBounds(southWest, northEast);
// move camera
pMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 40));
// Remove listener to prevent position reset on camera move.
pMap.setOnCameraChangeListener(null);
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_poi_map, menu);
return true;
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded(new LatLng(0.0, 0.0));
}
private void setUpMapIfNeeded(LatLng coord) {
// Do a null check to confirm that we have not already instantiated the map.
if (pMap == null) {
// Try to obtain the map from the SupportMapFragment.
pMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (pMap != null) {
setUpMap(coord);
}
}
}
private void setUpMap(LatLng userCoord) {
pMap.addMarker(new MarkerOptions()
.position(userCoord)
.title("Your location")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_user)));
pMap.animateCamera(CameraUpdateFactory.newLatLng(userCoord));
/* public static CameraUpdate newLatLngZoom (LatLng latLng, float zoom)
* Returns a CameraUpdate that moves the center of the screen to a latitude
* and longitude specified by a LatLng object, and moves to the given zoom
* level.
* Parameters
* latLng a LatLng object containing the desired latitude and longitude.
* zoom the desired zoom level, in the range of 2.0 to 21.0.
* Values below this range are set to 2.0, and values above it are set to 21.0.
* Increase the value to zoom in. Not all areas have tiles at the largest zoom levels.
* Returns
* a CameraUpdate containing the transformation.
*/
pMap.animateCamera(CameraUpdateFactory.newLatLngZoom(userCoord, 15));
}
}
This is a common question and I can never find a good answer for anyone so I'll do my best to help.
This sounds like you are missing the source code for Android. You need to download the Sources for Android SDK in Eclipse with the SDK Manager.
Open the SDK Manager in Eclipse
Find the version of android you want the source for. In this example, Android 4.2 (API17)
Check the box Sources for Android SDK
Click Install # packages
For example
After that, run your program and get to the point that you get that error. Now you will need to attach the documentation you've downloaded
Short
Click the button Edit Source Lookup Path
Click the Default folder
Click Add
Select File System Directory and click OK
Locate your downloaded source code. In this example, look for android-17 for API17. It will be in a directory such as adt-bundle\sdk\sources\android-17
Click OK a few times and your source is now linked.
Long
Click the button Edit Source Lookup Path
Click the Default folder and click Add
Select File System Directory and click OK
Locate your downloaded source code. In this example, look for android-17 for API17. It will be in a directory such as adt-bundle\sdk\sources\android-17
Click OK twice and it should look something like this
Click OK and enjoy your source code
This usually means that you are unable to access the source code whose bytecode is being called. In order to list out the exception you would need the original source which unfortunately is usually unavailable in jar formats.
Your option is to update the .jar file by updating your Android SDK with correct Rev’s and let it compile again to fix the issue.

Android, Google Maps won't show

I'm making an app that needs to show a location that I define with latitude and longitude. Everything goes fine, it opens Google maps in my app screen but the maps won't show up!
This is the code I use...
public class MapsActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//vraag custom title bar
requestCustomTitle();
setContentView(R.layout.mapsactivity);
//Titel dynamisch invullen volgens taalvoorkeuren, roept methode setCustomTitle op
setCustomTitle(getResources().getString(R.string.MapsTitel));
showZoom();
locate(getIntent().getStringExtra("kantoorLat"), getIntent().getStringExtra("kantoorLng"));
addMarker();
}
/*
* De methode showZoom zorgt ervoor dat de zoombuttons worden getoond
*/
private void showZoom(){
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
}
/*
* De methode locate zorgt ervoor dat de juiste locatie wordt getoond
*/
private void locate(String strlat, String strlng){
mc = mapView.getController();
String coordinates[] = {strlat,strlng};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
/*
* De methode addMarker zorgt ervoor dat er een indicator staat op de locatie
*/
private void addMarker(){
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
}
protected boolean isRouteDisplayed(){
return false;
}
class MapOverlay extends com.google.android.maps.Overlay{
#Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
super.draw(canvas, mapView, shadow);
Point screenPts = new Point();
mapView.getProjection().toPixels(p,screenPts);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.accentindicator);
canvas.drawBitmap(bmp, screenPts.x+7, screenPts.y-19, null);
return true;
}
}
MD5 key will not work on different machines.
You need to generate MD5 debug key for the current SDK that you are using.
Generate the debug key for your current machine and try again.
Get a API key here
http://code.google.com/apis/maps/signup.html
Put the following rule in your AndroidManifest
<uses-permission android:name="android.permission.INTERNET" />
Check the following blog entry that lists down the reasons that might cause this issue.
http://blog.doityourselfandroid.com/2011/01/18/using-google-maps-in-your-android-app/
Besides the activity, its also the manifest, the layout or the API key that can be invalid.
In short
The Android SDK needs to be setup to
support Google Maps.
A MapView
component needs to be added to your
layout, containing a valid Google
Maps API key
The Activity that will
be responsible for showing the map
needs to extend from MapActivity
The
application manifest needs to be
setup with the
android.permission.INTERNET
permission
The application manifest
needs to be setup with the
com.google.android.maps library
In your case, it's most likely internet connectivity (permisson in manifest and/or emulator internet access) or an invalid API key. Keep in mind that the API key is linked to the certificate used to sign your APK.
You need to get the key to access Google map in your application and after getting key you have to add library in ue manifest file which will be installed automatic when u got the key.
I think its your emulator version problem.Android sdk 2.2 emulators some times doesnot show the exact location.Try to run emulator 2.1 .
Even using the Google API Introduction I have had problems like this.
I followed this tutorial and it worked for me:
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
Good luck,

Categories

Resources