Identify if point is in the polygon

Just tried Ray Casting algorithm which identifies point in polygon. This works perfect. Refer http://en.wikipedia.org/wiki/Point_in_polygon for thesis of Ray-Casting private boolean isPointInPolygon(LatLng tap, ArrayList<LatLng> vertices) { int intersectCount = 0; for (int j = 0; j < vertices.size() – 1; j++) { if (rayCastIntersect(tap, vertices.get(j), vertices.get(j + 1))) { intersectCount++; } } return ((intersectCount % … Read more

Google map for android my location custom button

See below xml file to custom button: <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” > <fragment android:id=”@+id/maps” android:name=”pl.mg6.android.maps.extensions.SupportMapFragment” android:layout_width=”match_parent” android:layout_height=”match_parent” /> <LinearLayout android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:layout_marginLeft=”10dp” android:layout_marginRight=”10dp” android:layout_marginTop=”5dp” > <ImageView android:id=”@+id/imgMyLocation” android:layout_width=”40dp” android:layout_height=”40dp” android:scaleType=”fitXY” android:src=”https://stackoverflow.com/questions/23883235/@drawable/track_my_location” /> </LinearLayout> </RelativeLayout> Then in java class, declare your location button: private ImageView imgMyLocation; imgMyLocation = (ImageView) findViewById(R.id.imgMyLocation); Click Event: … Read more

get latitude and longitude with geocoder and android Google Maps API v2

Try this solution using this example url: http://maps.google.com/maps/api/geocode/json?address=mumbai&sensor=false which returns data in json format with lat/lng of address. private class DataLongOperationAsynchTask extends AsyncTask<String, Void, String[]> { ProgressDialog dialog = new ProgressDialog(MainActivity.this); @Override protected void onPreExecute() { super.onPreExecute(); dialog.setMessage(“Please wait…”); dialog.setCanceledOnTouchOutside(false); dialog.show(); } @Override protected String[] doInBackground(String… params) { String response; try { response = getLatLongByURL(“http://maps.google.com/maps/api/geocode/json?address=mumbai&sensor=false”); … Read more

Change position of Google Maps API’s “My location” button

You can get the “My Location” button and move it, like : public class MapFragment extends SupportMapFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mapView = super.onCreateView(inflater, container, savedInstanceState); // Get the button view View locationButton = ((View) mapView.findViewById(1).getParent()).findViewById(2); // and next place it, for exemple, on bottom right (as … Read more

Is there a way to implement rounded corners to a Mapfragment?

I know it’s an old post, but you can try using Cards like so: <android.support.v7.widget.CardView android:layout_width=”300dp” android:layout_height=”350dp” android:layout_gravity=”center_horizontal|center_vertical” android:layout_marginLeft=”10dp” android:layout_marginRight=”10dp” android:layout_marginTop=”20dp” app:cardCornerRadius=”12dp” app:cardElevation=”12dp”> <fragment android:id=”@+id/map” android:name=”com.google.android.gms.maps.SupportMapFragment” android:layout_width=”match_parent” android:layout_height=”match_parent” /> </android.support.v7.widget.CardView>

Replace default Android Maps API v2 Change MyLocation icon

my simple solution way is just disable “my location” of Google map and create ImageView on Map with my icon then capture ImageView with onClick and getMyLocation , animateCamera in onClick this.mGoogleMap.getUiSettings().setMyLocationButtonEnabled(false); this.mGoogleMap.setMyLocationEnabled(true); . @Override public void onClick(final View v) { Location location = this.mGoogleMap.getMyLocation(); if (location != null) { LatLng target = new LatLng(location.getLatitude(), … Read more

custom info window adapter with custom data in map v2

Try this windowlayout.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:orientation=”vertical”> <TextView android:id=”@+id/tv_lat” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> <TextView android:id=”@+id/tv_lng” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> </LinearLayout> MainActivity.java public class MainActivity extends FragmentActivity { GoogleMap googleMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Getting reference to the SupportMapFragment of activity_main.xml SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // Getting GoogleMap … Read more

Android: How to draw route directions google maps API V2 from current location to destination

This works great for me: It’s not my code, I took it from a great answer at stackoverflow but I can’t find this answer now, so here is the code: Add this class to your project: package …; import java.io.InputStream; import java.util.ArrayList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import … Read more