This is my code (bellow),
how to remove geopoints form code, and read it from sqlite from server? i have more than 1000 geopoints so my code is too long.
I have created datebase allready, but dont know how to connect it from server.
public class SimpleMap extends MapActivity {
private MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
MyLocationOverlay myLocationOverlay;
SimpleItemizedOverlay itemizedOverlay2;
SimpleItemizedOverlay itemizedOverlay;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
GeoPoint hr = new GeoPoint((int) (44.715513 * 1E6),
(int) (16.545410 * 1E6));
mapView.getController().animateTo(hr);
mapView.getController().setZoom(7);
mapOverlays = mapView.getOverlays();
myLocationOverlay = new FixedMyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
mapView.postInvalidate();
drawable = getResources().getDrawable(R.drawable.icon2);
itemizedOverlay2 = new SimpleItemizedOverlay(drawable, mapView);
itemizedOverlay2.setShowClose(true);
itemizedOverlay2.setShowDisclosure(false);
itemizedOverlay2.setSnapToCenter(false);
GeoPoint point1000 = new GeoPoint((int) (34.109798 * 1E6),
(int) (25.242270 * 1E6));
OverlayItem overlayItem1000 = new OverlayItem(point1000,
"point1000", "some text");
itemizedOverlay2.addOverlay(overlayItem1000);
mapOverlays.add(itemizedOverlay2);
Connecting to a remote database from a mobile device is a bad idea for a number of reasons, such as performance, security, and app extensibility. A quick search on SO will turn up many results that come to the same conclusion.
If you have control over the server, it would be best to set up a simple Web service that your app can use to retrieve geopoints. Then, rather than connecting to a database, your app would connect to a URL (e.g., using HttpUrlConnection) and download the location data. The server will need to send them in a format that is easy for your app to parse, such as a comma-separated list:
-82.8883,25.92834
2.5057,-60.90711
...
For each pair of points, create a GeoPoint, wrap it in an OverlayItem, and then add it to your Overlay.
Related
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Best Way to Add Map Pins to Google Map Android
How to add pin and if clicked show balon with info address or city which I have custom getOverlay() in google maps API android.
Below my code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_map);
mapView = (MapView) findViewById(R.id.map_view);
GeoPoint gpStart = new GeoPoint((int) (-6.31689 * 1E6),
(int) (106.74040 * 1E6));
GeoPoint gpEnd = new GeoPoint((int) (-6.29729 * 1E6),
(int) (106.78386 * 1E6));
Route r = direction(gpStart, gpEnd);
RouteOverlay rOverlay = new RouteOverlay(r, Color.RED);
mapView.getOverlays().add(rOverlay);
mapView.getController().animateTo(gpStart);
mapView.getController().setZoom(15);
mapView.setBuiltInZoomControls(true);
}
My code have edited, Code in above i get from here and work for me, but not show pin on location. I know to put pin wich if code is standart from google maps V1. Just add overlay. But my problem is I get map from json array. So i want to add pin in location(geopoint) and if i click i get info address.
Thanks.
If you're using the Google Maps Android API v2, which you should do, it's documented here.
private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));
Borrowing this code from several different tutorials on how to use Google maps on Android, I ran into a problem that "R.drawable.marker cannot be resolved or is not a field"
R.java is not being imported via the known bug in Eclipse.
public void onStart() {
super.onStart();
// Create an ItemizedOverlay to display a list of markers
Drawable defaultMarker = getResources().getDrawable(R.drawable.marker);
HelloItemizedOverlay placesItemizedOverlay = new HelloItemizedOverlay (defaultMarker, this);
GeoPoint point =new GeoPoint((int)(41.856451 * 1E6),
(int)(-87.604864 * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "Line 1", "Line 2");
List<Overlay> mapOverlays = mapView.getOverlays();
placesItemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(placesItemizedOverlay);
// mapView.getOverlays().add(placesItemizedOverlay);
}
You need to have a marker.png (or marker.jpeg or whatever) file in one or more of the drawable* directories in your project.
I am using OsmDroid for my Android application. I am setting a IGeoPoint as follows
IGeoPoint point2 = new IGeoPoint() {
public int getLongitudeE6() {
return 51475022;
}
public int getLatitudeE6() {
return -300322;
}
};
mapController.animateTo(point2);
this took me to deep blue sea. Whereas when I use google.mapview and set geopoint in following way
myMapController.animateTo(new GeoPoint((int) (51.475022 * 1E6),
(int) (-0.300322 * 1E6)));
it takes me to where I want
What's wrong with osmdroid?
Why are you trying to create a constructor for an Interface?
The Osmdroid GeoPoint is a class which implements this interface. You just need to instantiate a GeoPoint, like this:
GeoPoint gPt = new GeoPoint(51500000, -150000); // latitude, longitude
Then pass this to your .animate()
I have an android app that takes an array from a website
{"d":[{"latitude":-1.0,"longitude":-1.0,"time":"07:14 PM 01/18/2038","most_recent":"1","user_id":"4e3f2c6659f25a0f8400000b"},{"latitude":-1.0,"longitude":-1.0,"time":"07:14 PM 01/18/2038","most_recent":"0","user_id":"4e3f2c6659f25a0f8400000b"},{"latitude":-1.0,"longitude":-1.0,"time":"07:14 PM 01/18/2038","most_recent":"0","user_id":"4e3f2c6659f25a0f8400000b"},{"latitude":34.0608,"longitude":-118.454,"time":"07:14 PM 01/18/2038","most_recent":"1","user_id":"4e3da65e59f25a3956000005"},{"latitude":34.0608,"longitude":-118.454,"time":"07:14 PM 01/18/2038","most_recent":"0","user_id":"4e3da65e59f25a3956000005"},{"latitude":34.0608,"longitude":-118.454,"time":"07:14 PM 01/18/2038","most_recent":"0","user_id":"4e3da65e59f25a3956000005"}]}
as you can see each item has a latitude and longitude component as well as an id.
How do I modify this program to show either a green pin R.drawable.greenpin or a blue pin R.drawable.bluepin for "user_id":"4e3f2c6659f25a0f8400000b" or "user_id":"4e3da65e59f25a3956000005" for each of the items in the array ( should be three blue pins and three green pins at these locations)
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.greenpin);
canvas.drawBitmap(bmp,screenPts.x,screenPts.y-50,null);
return true;
}
}
//to add the location marker
MapOverlay mapOverlay=new MapOverlay();
List<Overlay> listOfOVerlays=mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
The method that I have confuses me a bit because it draws the point based on the screen point. I would rather add these points by inserting the pins by the longitude and latitude of the arrays.
I don't understanding what u want but in my case this code work for me, for put marker in appropriate lat,long address.
myPoint = new GeoPoint(((int) LATITUDE_Add) * 1E6),(int)LONGITUDE_Add) * 1E6));
drawable = getResources().getDrawable(R.drawable.marker_blue);
itemizedoverlay = new MapOverLay(drawable, MapPage.this, mapview);
OverlayItem overlayitem = new OverlayItem(myPoint, address, "");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
mapview.getController().animateTo(myPoint);
Thnx.
Is it possible to make 2 MapView on one Activity ?
If so, How to make it ?
I've tried but no luck.
Thanks in advance.
The short answer is no.
Currently Android supports only one MapView per MapActivity.
yes possible, I used this code for two different kinds of maps------ 1. for getting gps location------2. for getting some location when it is searched by its area/city/country name. The code is,
public void mapDisplay(double lat, double lng, int arg){
if(arg == 1){
mapView = (MapView)findViewById(R.id.map_view);
}
else if (arg ==2 ){
mapView = (MapView)findViewById(R.id.map_view2);
}
mapView.setBuiltInZoomControls(true);
//mapView.setStreetView(true);
//mapView.setTraffic(true);
//mapView.setSatellite(true);
// to display the pin point
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
GeoPoint point = new GeoPoint((int) (lat * 1E6), (int)(lng * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "", "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapView.getController().setZoom(18);
mapView.getController().setCenter(point);
mapView.getController().animateTo(point);
mapView.invalidate();
}
Note: Make sure that you have set the ContentViews before calling this method and
int arg
is used here to indicate that which mapView is going to be called.....I used