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"));
Related
Currently migrating an Android app using Google Maps to Google Maps Android v2; I want the map to display the built-in location marker, as well as custom markers.
With the previous library, I used to draw the location marker 'below' custom markers, with
mapView.setReticleDrawMode(ReticleDrawMode.DRAW_RETICLE_UNDER);
I can't find a similar option in the new API. Did I miss something?
After a bit a searching, I couldn't find such an option.
I finally removed the location pin, and added a similar Marker and Circle to the map; since it is a classic Marker, it appears below the other markers.
map.setMyLocationEnabled(false);
// ...
// get the current location with Android LocationManager in some way
// ...
// then draw it on the map when it changes:
if (null == getMyLocation())
return;
if (null != locationMarker) {
locationMarker.remove();
}
if (null != locationCircle) {
locationCircle.remove();
}
LatLng loc = getMyLocation();
locationMarker = map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.blue_pin_12))
.position(getMyLocation()).anchor(0.5f, 0.5f));
float accuracy = getMyLocationAccuracy();
locationCircle = map.addCircle(new CircleOptions().center(loc)
.radius(accuracy)
.strokeColor(Color.argb(255, 0, 153, 255))
.fillColor(Color.argb(30, 0, 153, 255)).strokeWidth(2));
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.
If there are values for Longitude and latitude how to map these values on GoogleMaps.Please give me links to this..
Ex: Longitude:12.93434334 Latitude:144.12121212
How to map these values on google map and get the position
If you mean to set/display map at particular coordinates you need to get MapController from MapView and set/animate to center you wish.
MapView view = (MapView)findViewById(id);
MapController controller = view.getController();
GeoPoint gp = new GeoPoint(lat, lon);
controller.setCenter(gp);
// controller.animateTo(gp); alternatively...
I am facing a problem with the google map search. I have mad a app through which i can see a location in google map on my emulator which is set in the code as:
int lat = (int)(22.3666667*1000000);
int lng = (int)(91.8000000*1000000);
GeoPoint pt = new GeoPoint(lat,lng);
This works fine.
Now i want to search a location dynamically i.e. i have a editbox(Location_For_Search) and a button(Find_Location_Button). So when i write some location in editbox and press the button then it will show the location in google map with a marker on location. How can i do this?
Please any one help me.
With best wishes
Md. Fazla Rabbi
Use the geocoder:
Geocoder geo = new Geocoder(this);
List<Address> addr;
try
{
addr = coder.getFromLocationName(yourEditTextaddr, 10);
Address loc = addr.get(0);
loc.getLatitude();
loc.getLongitude();
point = new GeoPoint((int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
return point;
}
I can take my location with myLocationOverlay easily, and I want to set as a center of my location, I tried map controller:
MapController mc = myMap.getController();
mc.animateTo();
mc.setCenter(myLocOverlay.getMyLocation());
these code didnt work so I changed
p = new GeoPoint((int) (myLocOverlay.getMyLocation().getLatitudeE6()), (int) (myLocOverlay.getMyLocation().getLongitudeE6()));
mc.setCenter(p);
But there is no good news. I took null pointer exception then I assigned new location before myLocationOverlay() but its not working.. Thanks for advance..
The animateTo can be used for this,
GeoPoint point = this.currentLocationOverlay.getMyLocation();
if(point==null)
return;
//center map on that geopoint
mc.animateTo(point);