CodeSolution

Please wait...

How We Can Use Use Google Map In Android Studio Project ?

How We Can Use Use Google Map In Android Studio Project ?

@Google  @ Maps  @Google API key  @location  @Sydney   @API  

If you want to use Google Maps in your app.

  • Create New Project and select google Google Maps Activity.
  • Run The Program.
  • If you run this program you will not have any output shown.

If we want to show the output, then we need to use Google API key.

  • Copy this Link from google_maps_api.XML Page and paste your browser.
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=AD:12:FF:A1:00:4E:E2:9A:17:6A:86:47:32:95:E0:03:7D:0B:C1:A7%3Bwaytofeed.wapptech.com.google_map_project
  • Select yes both Radio button.
  • Select Agree and Continue.
  • Create API Key.
  • Copy this API Key and paste the project  google_maps_api.xml page.
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyAPz2gDpX-YbKXe5RYzEH4f9DlvqDZyfe4</string>
  • Run the project.
  • But the default location set which is set here is from Sydney.

If we want to change his location.

  • Search in-browser latitude and longitude of any city.
  • Copy This latitude and longitude number and paste in onMapReady function.
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(22.7196, 75.8577);
  • Run the Project. 

All Codes:)

google_maps_api:-

<resources>
    <!--
    TODO: Before you run your application, you need a Google Maps API key.

    To get one, follow this link, follow the directions and press "Create" at the end:

    https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=AD:12:FF:A1:00:4E:E2:9A:17:6A:86:47:32:95:E0:03:7D:0B:C1:A7%3Bwaytofeed.wapptech.com.google_map_project

 
    -->
    <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyAPz2gDpX-YbKXe5RYzEH4f9DlvqDZyfe4</string>
</resources>

MainActivity.java:)

package waytofeed.wapptech.com.google_map_project;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

    }
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(22.7196, 75.8577);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

Comments 0

Reply

>