我正在开发一个旅游应用程序.我想在每个地方添加谷歌地图标记.如何添加标记



我正在开发一个旅游应用程序。我想在每个地方添加谷歌地图标记。如何添加标记。这是我的布局代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
    android:id="@+id/icon"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:scaleType="fitXY"
    android:padding="5dp" />
    <LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
   <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
    <TextView
        android:id="@+id/item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:padding="2dp"
        android:textStyle="bold"
        android:background="#737c8c"
        android:text="aaaaaaaaaaaa"
        android:textSize="20dp"
        android:layout_gravity="center_horizontal"
        android:textColor="#33CC33" />
<TextView
    android:layout_width="50dp"
    android:id="@+id/text_Address"
    android:layout_height="50dp"
     android:background="@drawable/icon" /> //Here is the Text view with I attatched the marker icon named "icon" and I want that when I click on this icon google map with marker appears
  </LinearLayout>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="4dp"/>
        </LinearLayout>
        </LinearLayout>

这是我运行应用程序时的屏幕截图。我希望当我单击标记图标时,会出现带有标记的地图。截图

这是我的主要活动课

package com.alphadroid.pakistantourism;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
 ImageView imageViewKPK,imageView_Punjab,imageView_sindh,imageView_balochistan;

String[] sindh_place_name ={
        "Mazar e Quaid",
        "Mohenjo Daro",
        "Clifton Beach Karachi",
        "Paf Mesuem"
};
String[] balochistan_place_name ={
        "Hanna Lake Quetta",
        "Gwadar",
        "Ziarat",
        "Chotok Khuzdar"
};
String[] sindh_place_description ={
        "Mazar-e-Quaid is the tomb of Quaid-e-Azam Muhammad Ali Jinnah who is the founder of Pakistan. He is the father of the nation and deserves a top place for his tomb which he is given rewarded with. The tomb is also the final resting place of Madir-e-Millat (Mother of the Nation), Fatima Jinnah who is the sister of Quaid-Azam. The first prime Minister of Pakistan, Liaquat Ali Khan is also buried here after his assassination in 1951. Fatima Jinnah and Liaquat Ali Khan are buried in the courtyard on the side where as Quaid-e-Azam has his last resting place in the center of the tomb.",
        "Mohenjo-Daro is one of the oldest known civilizations of the Ancient Indus Valley which was in place around 2600 BC. Mohenjo-Daro archeological site is in Sindh, province of Pakistan. It is regarded as the oldest urban settlement of the world which still has it remains in the today’s world. The Mohenjo-Daro got abandoned in the 19th century BC era and was rediscovered in 1922.",
        "Clifton Beach or Seaview is a beach in Karachi, Sindh, Pakistan located on the Arabian Sea. It is one of the neighborhoods of Clifton, Saddar Town. It was the World's most popular silver-sand beach and health resort during 20th century but in 2003 it was affected by an oil spill. The beach has attractions for families and tourists, including beachside horse and camel rides, amusement parks, restaurants, and swimming in the Arabian Sea.",
                "PAF Museum is located adjacent to the PAF Base Faisal on the main shahrah-e-Faisal. The museum was inaugurated on the 14 August, 1997 by the then Chief of the Air Staff Air Chief Marshal Abbas Khattak; and subsequently opened to the general public in October, 1997. A huge archives gallery houses the other rare relics like the Viking - Quaid-e-Azam’s aircraft, an Indian Gnat aircraft which was force landed at Pasroor in 1965 war and many more. Four PCs have also been placed inside the archives gallery, which provide information about different aspects of the PAF."
};
String[] balochistan_place_description ={
        "Hanna Lake is considered as one of the beautiful Lake in Pakistan. This Lake is constructed by British Empire near Quetta city. A small dam Surrpull was also constructed by British Empire with this lake on the main Urak road for providing inflow of water into the lake from the mountains of Zargoon coming from rainfalls, melting of snow and streams through main waterway.",
        "Gwadar lies on the Arabian Sea coast of Balochistan Province in southwestern Pakistan. It is strategically located between three increasingly important regions: the oil-rich Middle East, heavily populated South Asia and the economically emerging and resource-laden region of Central Asia. The Gwadar Port is expected to generate billions of dollars in revenues and create at least two million jobs.n" +
                "Gwadar, “The Future of Pakistan”, is a Balochi word which means “Door of Wind”. However, looking into the future, it can be referred to as the “Door of Prosperity Wind”.",
        "Ziarat is a district and a famous hill station located in the north of province of Balochistan. It is a famous holiday resort of Balochistan. Nearly every trip from Karachi to Quetta stops at Ziarat. Khalifat Hills are the highest peak with an altitude of 11,400 feet in Ziarat district. Ziarat has the highest ‘Human Development Index’ of all districts of Balochistan.",
        "Chotok is a hidden paradise of Balochistan, located at a distance of 80 km from Khuzdar. The area is endowed with magnificent rocky mountains, dream water pools, dates forestry and breathtaking views of waterfalls."
};
String[] kpk_place_name ={
        "Naran Kaghan Valley",
        "Swat Valley",
        "Upper Dir District",
        "Chitral"
};
String[] punjab_place_name ={
        "Minar e Pakistan",
        "Faisal Masjid",
        "Murree",
        "Neelum Valley, Azad Kashmir"
};
String[] punjab_place_description ={
        "Minar-e-Pakistan is situated in Iqbal park Lahore, at the intersection of circular road and Multan road, surrounded by the modern park where people visit day and night, which includes mountains and artificial lake as well. Visitors can climb up stairs for a beautiful view of Lahore city and its surroundings." +
                "When you come to Lahore I suggest its first place that you want to visit, it’s very beautiful and huge tower depicting the memories of memorandum of Pakistan.",
        "Completed in 1986, the Faisal Masjid (also known as Shah Faisal Masjid) is an exceptionally large and unique masjid in Islamabad. Designed by a Turkish architect who won an international competition for the honor, Faisal Masjid is shaped like a desert Bedouin's tent and functions as the national masjid of Pakistan.",
        "Murree is located in the Province of Punjab is a beautiful city enclosed with astonishing snow.  Murree is in a subdivision of Rawalpindi District and also consist of the Margalla Hills around Islamabad. Murree acts as a hub for Pakistani’s tourism sector. It is among the most preferred visited locations in Pakistan. Murree is also a famous holiday spot for honeymoon.",
        "Opposite to the Keran sector of Indian-held Kashmir. From the Chella Bandi Bridge – just north of Azaad Kashmir’s capital Muzaffarabad – to Tau Butt, a valley stretches out for 240 kilometres; it is known as the Neelum Valley (literally, the Blue Gem Valley)." +
                "Neelum is one of the most beautiful valleys of Azaad Kashmir, and it hosts several brooks, freshwater streams, forests, lush green mountains, and a river. Here, you see cataracts falling down the mountains; their milky-white waters flowing over the roads and splashing against the rocks, before commingling with the muddy waters of River Neelum."
};
String[] kpk_place_description ={
        "Naran is a medium sized town in upper Kaghan Valley in Mansehra District of Khyber Pakhtunkhwa province of the Pakistan. It is located 119 kilometers from Mansehra city at the altitude of 8,202 feet. Naran is one of the most scenic towns in Pakistan, attracting thousands of tourists, trekkers, photographers and nature-enthusiast, every year",
        "Swat; is a river valley and an administrative district in the Khyber Pakhtunkhwa Province of Pakistan" +
                "It is the upper valley of the Swat River, which rises in the Hindu Kush range." +
                "The capital of Swat is Saidu Sharif, but the main town in the Swat valley is Mingora." +
                " It was a princely state, the Yusafzai State of Swat, until 1969, when it was dissolved along with the states of Dir and Chitral and made part of Khyber Pakhtunkhwa, then known as North West Frontier Province." +
                " The valley is populated mostly by ethnic Pashtuns and Gujjar and Kohistani communities. The languages spoken in the valley are Pashto, Gojri, Torwali and Kohistani. With high mountains, green meadows, and clear lakes, it is a place of great natural beauty and is popular with tourists." +
                " Queen Elizabeth II during her visit to the The Yusafzai State of Swat called it the Switzerland of the east. Swat is surrounded by Chitral, Upper Dir and Lower Dir in the West, Gilgit-Baltistan in North Kohistan, Buner and Shangla in the East and south East.",
        "Upper Dir is one of the 26 districts of Khyber Pakhtunkhwa. At the time of independence, Dir was a princely state ruled by Nawab Shah Jehan Khan." +
                " It was merged with Pakistan in 1969 and later on declared as a district in 1970." +
                " In 1996, it was bifurcated into Upper and Lower Dir districts. " +
                "This district is situated in the northern part of Pakistan. " +
                "It borders Chitral district and Afghanistan on the north and north west and Swat district to the east, and on the south by Lower Dir District",
                "Chitral, also spelled Chetrar, translated as field, is the capital of the Chitral District, situated on the western bank of the Chitral River, in Khyber Pakhtunkhwa, Pakistan." +
                " It also served as the capital of the princely state of Chitral until 1969. " +
                "The town is at the foot of Tirich Mir, the highest peak of the Hindu Kush, which is 25,289 ft high." +
                " It has a population of 20,000. The elevation of the valley is 3,700 ft",
};
Integer[] kpk_imgid={
        R.drawable.kaghan,
        R.drawable.swat,
        R.drawable.dir_upper,
        R.drawable.chitral,
};
Integer[] punjab_imgid={
        R.drawable.minar_e_pak,
        R.drawable.faisla_masjid,
        R.drawable.murree,
        R.drawable.neelam_valley,
};
Integer[] sindh_imgid={
        R.drawable.mazare_quaid,
        R.drawable.mohenjo_daro,
        R.drawable.clifton_beach,
        R.drawable.paf_mesuem,
};
Integer[] balochistan_imgid={
        R.drawable.hanna_lake_quetta,
        R.drawable.gwadar_port,
        R.drawable.ziarat_balochistan,
        R.drawable.khuzdar,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imageViewKPK=(ImageView)findViewById(R.id.KPK);
    imageView_Punjab=(ImageView)findViewById(R.id.Punjab);
    imageView_sindh=(ImageView)findViewById(R.id.Sindh);
    imageView_balochistan=(ImageView)findViewById(R.id.Balochistan);
    imageViewKPK.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent intent = new Intent(getApplicationContext(), Places.class);
            intent.putExtra("name_array",kpk_place_name);
            intent.putExtra("description_array",kpk_place_description);
            intent.putExtra("images_array",kpk_imgid);
            startActivity(intent);
        }
    });
    imageView_Punjab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getApplicationContext(), Places.class);
            intent.putExtra("name_array",punjab_place_name);
            intent.putExtra("description_array",punjab_place_description);
            intent.putExtra("images_array",punjab_imgid);
            startActivity(intent);
        }
    });
    imageView_sindh.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getApplicationContext(), Places.class);
            intent.putExtra("name_array",sindh_place_name);
            intent.putExtra("description_array",sindh_place_description);
            intent.putExtra("images_array",sindh_imgid);
            startActivity(intent);
        }
    });
    imageView_balochistan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent intent = new Intent(getApplicationContext(), Places.class);
            intent.putExtra("name_array",balochistan_place_name);
            intent.putExtra("description_array",balochistan_place_description);
            intent.putExtra("images_array",balochistan_imgid);
            startActivity(intent);
        }
    });
}}

这是地方类

   package com.alphadroid.pakistantourism;
   import android.app.Activity;
   import android.app.ListActivity;
   import android.content.Intent;
   import android.os.Bundle;
   import android.view.View;
   import android.widget.AdapterView;
   import android.widget.AdapterView.OnItemClickListener;
   import android.widget.ArrayAdapter;
   import android.widget.ListView;
   import android.widget.TextView;
 import android.widget.Toast;
 import java.util.Arrays;

 public class Places extends Activity{
ListView list;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     TextView textView_address=(TextView)findViewById(R.id.text_Address);
    Intent intent = getIntent();
    String[] place_name = intent.getStringArrayExtra("name_array");
    String[] place_description = intent.getStringArrayExtra("description_array");
    Object[] s = (Object[]) getIntent().getSerializableExtra("images_array");
    Integer[] newArray = Arrays.copyOf(s, s.length, Integer[].class);
    CustomAdapter adapter=new CustomAdapter(this, place_name,place_description, newArray);
    list=(ListView)findViewById(R.id.list);
    list.setAdapter(adapter);
}

}

在单击标记时尝试此操作:

/

/uri 应该像一个位置的完整 Web URL

String uri = "http://maps.google.com/";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

您应该创建一个具有 geo-URI 的 Intent 对象:



String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); context.startActivity(intent);如果要指定地址,则应使用另一种形式的 geo-URI:

geo:0,0?q=address

参考 : https://developer.android.com/guide/components/intents-common.html#Maps

最新更新