2

So eventually I have to come back here to ask it again. I googled a lot on this issue. There are so many solutions and they are very confusing. Moreover, most of them are done in Eclipse, they said to change path, intigrate it with eclipse and bla bla...

Problem Description:

In my application (in android studio), I have an item named Map view and I want that as soon as a user clicks on it, it should take a map view page and locate that address (I have mentioned in my code) in the map. How could I do that?

DummyContent:

................................
................................
     static {
        // Add 4 sample items.
        addItem(new DummyItem("1", "Shopping center details"));
        addItem(new DummyItem("2", "Homepage"));
        addItem(new DummyItem("3", "Contact"));
        addItem(new DummyItem("4", "Map View"));
    }
.................................
..............................

ItemDetailFragment:

    .................
....................
 }else if(mItem.equals("4")){//4. Map View

                /*locate the following address in google map:
                Times Square
                Manhattan, NY 10036
                United States

                */
                 rootView = inflater.inflate(R.layout.fragment_map_detailed, container, false);
                WebView webview = (WebView) rootView.findViewById(R.id.webView2);

                webview.setWebViewClient(new WebViewClient());
                 }
..............................
......................

fragment_map_detailed.XML:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

</LinearLayout>
Riyana
  • 241
  • 13
  • 29

2 Answers2

1

You might want to display markers, that are placed on the map when you start an activity. Markers doesn't operate or adresses but on coordinates. For an adress you mentioned it will look like this:

@Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
    .position(new LatLng(40.758887, -73.985152))
    .title("The Times Square"));
}

more info about markers: https://developers.google.com/maps/documentation/android/marker more info about starting with map activities (you MUST look there if You haven't done it yet): https://developers.google.com/maps/documentation/android/start

Raptor42
  • 391
  • 2
  • 10
1

I would suggest you break your problem up into smaller parts. Your first problem is you need to get a location in lat lng from an address. For this you should use Geocoder. something like this answer

After that it is a matter of setting up a google map. For this you should follow the guides posted on developer.google.com

then use something like

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(locationFromGeocoder, 16));

to move the google map to the address you found in the geocoder.

You probably should not use a webview here. Native google map support is much better. Not sure why you keep finding eclipse projects as android studio is pretty much standard now.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
doubleA
  • 2,446
  • 22
  • 45
  • it's easier to get coords by going into maps.google.com, right-clicking on a location and clicking 'what is there' – Raptor42 Mar 28 '15 at 20:51
  • Not necessary in an android app that is what the geocoder is for. Then you can use any address you want in the future instead of hard coding the lat and long into the app. – doubleA Mar 28 '15 at 20:54