Android 台灣中文網

標題: eclipse 製作 googlemap 地圖家大頭針 [打印本頁]

作者: crazy8100890    時間: 2014-5-2 09:28
標題: eclipse 製作 googlemap 地圖家大頭針
我執行出來沒有大頭針,我該如何在地圖上加入大頭針
----------------------------------------------------------------------------------------------------------------------

googleMap.html

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript"
        src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
  function initialize() {
    var myLatlng = new google.maps.LatLng(25.018398,121.537796);  //地圖中心點
    var myOptions = {
           zoom: 17,
           center: myLatlng,
           mapTypeId: google.maps.MapTypeId.ROADMAP               //道路地圖
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

----------------------------------------------------------------------------------------------------------------------

MainActivity.java

package com.example.google;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;

public class MainActivity extends Activity {
        private static final String MAP_URL = "file:///android_asset/googleMap.html";
        private WebView webView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                setupWebView();
                this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);       
        }   
       
        private void setupWebView(){
                webView = (WebView) findViewById(R.id.webView1);
                webView.getSettings().setJavaScriptEnabled(true);      
                webView.loadUrl(MAP_URL);  
        }
}

----------------------------------------------------------------------------------------------------------------------

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Home" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="fill_parent"
        android:layout_height="400dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_weight="0.39" />

</RelativeLayout>
作者: wuyanyin    時間: 2014-7-29 13:29
謝謝分享...............大家加油!!
作者: fifish098    時間: 2014-9-23 10:44

幫你改了一下html

在 var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);之後加上
markers.push( new google.maps.Marker({
                                position: myLatlng,
                                map: map,
                                draggable: true
                            })
                        );
        markers[0].setAnimation(google.maps.Animation.BOUNCE); // 一直跳 一直跳 跳不停

詳細用法請看google map v3的說明吧
https://developers.google.com/maps/documentation/javascript/tutorial?hl=zh-tw

作者: fifish098    時間: 2014-9-23 10:47
幫你改了一下html

在 var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
這行之後加上
var markers = [];
        markers.push( new google.maps.Marker({
                                position: myLatlng,
                                map: map,
                                draggable: true
                            })
                        );
        markers[0].setAnimation(google.maps.Animation.BOUNCE); // 一直跳

詳細用法先去看google map v3的說明文件吧
https://developers.google.com/maps/documentation/javascript/tutorial?hl=zh-tw





歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1