You are on page 1of 28

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

A. PH N I :
Nu c m nh n c a b n than v vi c c tham quan, ti p c n v i mi tr doanh nghi p, c th l cng ty Enclave. ng

I. Gi i thi u v cng ty Enclave :

Cng ty Cng ngh ph n m m Enclave l m t trong nh ng cng ty gia cng ph n m m 100% v n n c ngoi ng trn a bn N ng (27 Hu nh Thc Khng- N ng).Cng ty ho t ng hon ton v i cng vi c gia cng ph n m m cho khch hng. Cng ty Cng ngh ph n m m Enclave l m t trong nh ng cng ty gia cng ph n m m 100% v n n c ngoi ng trn a bn N ng (27 Hu nh Thc Khng- N ng).Cng ty ho t ng hon ton v i cng vi c gia cng ph n m m cho khch hng. Cng ty th ng dnh Cc m ng h p tc, h tr cho sinh vin: - T ch c cc bu i seminar, workshop cho sinh vin v gi ng vin khoa o t o Qu c t v CNTT - Trao h c b ng hng n m. - Tuy n d ng sinh vin th c t p v tuy n d ng vi c lm. - Gp tri n khai ch ng trnh o t o v cc ho t ng lin quan khc.

II. C m nh n c a b n thn :
Khi tham quan mi tr ng doanh nghi p, th t s em nh n ra c nhi u i u. u tin em nh n th y cng ty Enclave l m t cng ty v i i ng nhn vin tr ,n ng ng v ti n ng. - Cng ty Enclave c t ch c kh ch t ch ,chia thnh nhi u phng v i cc ch c n ng, nhi m v khc nhau .M i phng th c hi n cc d n khc nhau. - Lnh o cng ty l nh ng ng i c kinh nghi m,ti n ng nh ng khng thi u s nhi t tnh trong cng vi c. i ng nhn vin tr , y ti n ng ,nhit tnh c th m ng v hon thnh t t cng vi c. c bi t l h c nh ng k n ng m m t t : lm vi c nhm,ngo i ng .. - Mi tr ng lm vi c thn thi n v i n n t ng ngoai ng t t.
SVTH : Tr Page 1

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

Mi tr ng lm vi c t i cng ty th t khc so v i s t ng t ng c a em.M t mi tr ng lm vi c m khng c v n ngoai ng t t th kh c th ha nh p t t. Sau khi c ti p c n v trao i v i anh ch l nhn vin c a cng ty,em hi u c r ng lm t t cng vi c th mnh khng ch hi u su m t ngn ng l p trnh,m t v n m ph i hi u nhi u i u h n nh ngo i ng , kh n ng lm nhm,... c bi t ph i c s thch ng nhanh v i mi tr ng.

B. PH N II :
I. M t ti :
xy d ng ng d ng b n

tr c tuy n s d ng ngn ng JAVA.

ti 39 : Nghin c u gi cng ngh Google Map API C s l thuy t :

II.

1. Gi i thi u : Google Maps (th i gian tr c cn g i l Google Local) l m t d ch v ng d ng v cng ngh b n tr c tuy n trn web mi n ph c cung c p b i Google v h tr nhi u d ch v d a vo b n nh Google Ride Finder v m t s c th dng nhng vo cc trang web c a bn th ba thng qua Google Maps API. N cho php th y b n ng s, ng i cho xe p, cho ng i i b (nh ng ng i ng n h n 6.2 d m) v xe h i, v nh ng a i m kinh doanh trong khu v c c ng nh kh p n i trn th gi i.

III.

Cng ngh :

1. Google map API l g? The Google Maps API cung c p cc d ch v web nh 1 giao di n yu c u d li u Maps API t 1 d ch v bn ngoi(d ch v c a Google) v s d ng n bn trong nh ng ng d ng b n c a chng ta(cc trang web). Cc d ch v ny c thi t k s d ng trong s lin k t v i b n . Cc d ch v web ny s d ng giao th c HTTP yu c u n cc URL c th , truy n cc tham s URL nh l truy n cc i s n d ch v . Ni chung cc d ch v ny tr v d li u trong yu c u HTTP nh JSON hay XML truy n v/hay x l b i ng d ng c a chng ta. Ex : 1 ki u yu c u d ch v web ni chung c c u trc nh sau:

SVTH : Tr

Page 2

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

http://maps.googleapis.com/maps/api/service/output?parameters

Trong :
Service : Ch Output : Ch

nh c th d ch v c yu c u. nh ki u nh d ng tr v (XML hay JSON)

2. Truy c p SSL: B n khng nh ng c th truy c p d ch v web Google API thng qua giao th c HTTPS. Ta c th thay i giao th c trong yu c u URL c a b n thnh https nh sau:
https://maps.googleapis.com/maps/api/service/output?parameters

HTTPS v tr ng

c ch cho ng d ng r ng n ch a d li u d ng nh y c m c a ng i dng trong yu c u.

i dng, nh

S d ng Google Map API by gi yu c u r ng b n ch nh ng d ng c a b n cs d ng 1 c m bi n (nh nh v GPS) xc nh v tr c a ng i dng trn b t k th vi n Map API no hay cc yu c u d ch v . y l i u c bi t quan tr ng v i thi t b di ng. N u ng d ng Google Map API c a b n s d ng b t k d ng no c a c m bi n xc nh v tr c a thi t b ang truy c p ng d ng c a b n. b n ph i khai bo n v i 1 gi tr true v i tham s c a c m bi n.Ch r ng th m ch n u ng d ng c a b n khng s d ng 1 c m bi n nh v , b n v n ph i thi t l p tham s sensor. 3. Xy d ng URL h p l : Chng ta c n d ch cc k t c bi t b i v t t c cc URL c n ph h p v i c u trc ch nh b i c t W3 Uniform Resource Identifier. N c ngh a l cc URL ch c ch a t p con c bi t c a cc k t ASCII, cc bi u t ng v a c ch v a c s quen thu c v m t s k t d tr cho dng nh cc k t i u khi n bn trong cc URL. B ng sau t ng h p cc k t :
Set Alphanumeric Unreserved Reserved Characters abcdefghijklmnopqrstuvwxyzA BCDEFGHIJKLMNOPQRSTUV WXYZ0123456789 -_.~ !*'();:@&=+$,/?%#[] URL usage Text strings, scheme usage (http), port (8080), etc. Text strings Control characters and/or Text Strings

T t c cc k t c m ha URL c m ha s 1 k t '%' v 2 k t gi tr th p l c phn t ng ng v i cc k t UTF-8 . V d , + trong UTF-8 c chuy n m


SVTH : Tr Page 3

Bo co th c t p nh n th c Duy
thnh %E4%B8%8A%E6%B5%B7%2B%E4%B8%AD%E5%9C%8B . Chu i ? chuy n thnh %3F+and+the+Mysterians.

GVHD : Tr nh Cng

and the Mysterians

4. S xc th c

u tin Map API :

Yu c u n cc d ch v web Map API b i ng d ng by gi yu c u ch k i n t s d ng 1 kha c m ha m Google cung c p cho b n cho m c ch . Ch k x l k t h p 1 URL v kha ch k v i nhau s d ng 1 thu t ton m ha,t o 1 ch k duy nh t. Ch k duy nh t ny cho php s ch v web c a chng ta xc th c r ng b t c trang no sinh ra yu c u m s d ng ID khch Map API c a b n c xc th c lm i u . Ch k khng nh ng duy nh t cho m i URL, m b o r ng cc yu c u s d ng ID khch khng th c ch nh s a m khng yu c u 1 ch k m i c t o ra. 5. X l ph n h i : Khi nh d ng chnh xc c a cu tr l i ring l v i m t yu c u d ch v web l khng c b o m (m t s y u t c th b m t hay nhi u a i m), b n khng nn gi nh r ng cc nh d ng c tr v cho b t k ph n ng nh t nh s l t ng t cho cc truy v n khc nhau. Thay vo , b n nn x l cc ph n ng v ch n gi tr thch h p thng qua cc bi u th c. Ph n ny bn v lm th no trch xu t cc gi tr t ng ng ph v i d ch v web. Cc d ch v Web c a Google cung c p cu tr l i l d hi u, nh ng khng hon ton thn thi n ng i dng. Khi th c hi n m t truy v n, thay v hi n th m t t p h p cc d li u, b n c th mu n trch xu t m t vi gi tr c th . Ni chung, b n s mu n phn tch ph n h i t cc d ch v web v gi i nn ch nh ng gi tr m b n quan tm. n phn tch c php m b n s d ng ph thu c vo li u b n c tr v u ra l XML ho c JSON. Phc p JSON, l c trong hnh th c c a cc i t ng Javascript, c th c x l trong vng Javascript chnh n trn my khch, phc p XML ph i cx l b ng cch s d ng m t b x l XML v m t ngn ng truy v n XML gi i quy t cc y u t trong nh d ng XML. Chng ti s d ng XPath trong cc v d sau y, v n th ng c h tr trong cc th vi n x l XML.

IV.

Cch xy d ng ch

ng trnh :

SVTH : Tr

Page 4

Bo co th c t p nh n th c Duy 1.
Tr

GVHD : Tr nh Cng

nh h

ng :

c tin ta ph i xy d ng 2 gi h tr cho ng d ng l :

+ Gi org.netbeans.saas : ch a cc l p lm nhi m v nh ngh a cc k t n i v i GooglemapServer trong l p RestConnection v nh ngh a cch x l cc phc p t GooglemapServer trong l p RestResponse. + Gi org.netbeans.saas.google : ch a l p GoogleMapService th c hi n k t n i t i GooglemapServer, g i yu c u v nh n phc p t GooglemapServer.V 1 property googlemapservice ch a API_KEY do Google cung c p. Ti p theo ta t o 1 file JSP trang web tr c tuy n. hi n th d li u do Google map API phc p ln

2. Th c thi :
a. Xy d ng gi org.netbeans.saas : + T o l p RestConnection:
package org.netbeans.saas;

import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.Authenticator; import java.net.HttpURLConnection;
SVTH : Tr Page 5

Bo co th c t p nh n th c Duy
import java.net.URL; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; public class RestConnection {

GVHD : Tr nh Cng

static { //set the identification of the client System.setProperty("http.agent", System.getProperty("user.name") + " (from NetBeans IDE)"); } private HttpURLConnection conn; private String date; /** Creates a new instance of RestConnection */ public RestConnection(String baseUrl) { this(baseUrl, null, null); } /** Creates a new instance of RestConnection */ public RestConnection(String baseUrl, String[][] params) { this(baseUrl, null, params); } /** Creates a new instance of RestConnection */
SVTH : Tr Page 6

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

public RestConnection(String baseUrl, String[][] pathParams, String[][] params) { try { String urlStr = baseUrl; if (pathParams != null && pathParams.length > 0) { urlStr = replaceTemplateParameters(baseUrl, pathParams); } URL url = new URL(encodeUrl(urlStr, params)); conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setDefaultUseCaches(false); conn.setAllowUserInteraction(true); SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"); date = format.format(new Date()); conn.setRequestProperty("Date", date); } catch (Exception ex) { Logger.getLogger(RestConnection.class.getName()).log(Level.SEVERE, null, ex); } } public void setAuthenticator(Authenticator authenticator) { Authenticator.setDefault(authenticator); }
SVTH : Tr Page 7

Bo co th c t p nh n th c Duy
public String getDate() { return date; } public RestResponse get() throws IOException { return get(null); }

GVHD : Tr nh Cng

public RestResponse get(String[][] headers) throws IOException { conn.setRequestMethod("GET"); return connect(headers, null); } public RestResponse head() throws IOException { return get(null); } public RestResponse head(String[][] headers) throws IOException { conn.setRequestMethod("HEAD"); return connect(headers, null); } public RestResponse put(String[][] headers) throws IOException { return put(headers, (InputStream) null); } public RestResponse put(String[][] headers, String data) throws IOException { InputStream is = null; if(data != null)

SVTH : Tr

Page 8

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

is = new ByteArrayInputStream(data.getBytes("UTF-8")); return put(headers, is); } public RestResponse put(String[][] headers, InputStream is) throws IOException { conn.setRequestMethod("PUT"); return connect(headers, is); } public RestResponse post(String[][] headers) throws IOException { return post(headers, (InputStream) null); } public RestResponse post(String[][] headers, String data) throws IOException { InputStream is = null; if(data != null) is = new ByteArrayInputStream(data.getBytes("UTF-8")); return post(headers, is); } public RestResponse post(String[][] headers, InputStream is) throws IOException { conn.setRequestMethod("POST"); return connect(headers, is); } public RestResponse post(String[][] headers, String[][] params) throws IOException { conn.setRequestMethod("POST"); conn.setRequestProperty("ContentType", "application/x-www-form-urlencoded");

SVTH : Tr

Page 9

Bo co th c t p nh n th c Duy
String data = encodeParams(params);

GVHD : Tr nh Cng

return connect(headers, new ByteArrayInputStream(data.getBytes("UTF-8"))); }

public RestResponse delete(String[][] headers) throws IOException { conn.setRequestMethod("DELETE"); return connect(headers, null); private RestResponse connect(String[][] headers, InputStream data) throws IOException { try { // Send data setHeaders(headers);

String method = conn.getRequestMethod();

byte[] buffer = new byte[1024]; int count = 0;

if (method.equals("PUT") || method.equals("POST")) { if (data != null) { conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); while ((count = data.read(buffer)) != -1) {

SVTH : Tr

Page 10

Bo co th c t p nh n th c Duy
os.write(buffer, 0, count); } os.flush(); } } RestResponse response = new RestResponse(); InputStream is = conn.getInputStream();

GVHD : Tr nh Cng

while ((count = is.read(buffer)) != -1) { response.write(buffer, 0, count); } response.setResponseCode(conn.getResponseCode()); response.setResponseMessage(conn.getResponseMessage()); response.setContentType(conn.getContentType()); response.setContentEncoding(conn.getContentEncoding()); response.setLastModified(conn.getLastModified()); return response; } catch (Exception e) { String errMsg = "Cannot connect to :" + conn.getURL(); try { BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getErrorStream())); String line; StringBuffer buf = new StringBuffer();
SVTH : Tr Page 11

Bo co th c t p nh n th c Duy
while ((line = rd.readLine()) != null) { buf.append(line); buf.append('\n'); } errMsg = buf.toString(); } finally { throw new IOException(errMsg); } } }

GVHD : Tr nh Cng

private String replaceTemplateParameters(String baseUrl, String[][] pathParams) { String url = baseUrl; if (pathParams != null) { for (int i = 0; i < pathParams.length; i++) { String key = pathParams[i][0]; String value = pathParams[i][1]; if (value == null) { value = ""; } url = url.replace(key, value); } } return url;

SVTH : Tr

Page 12

Bo co th c t p nh n th c Duy
} private String encodeUrl(String baseUrl, String[][] params) { String encodedParams = encodeParams(params); if (encodedParams.length() > 0) { encodedParams = "?"+ encodedParams; } return baseUrl + encodedParams; }

GVHD : Tr nh Cng

private String encodeParams(String[][] params) { String p = ""; if (params != null) { for (int i = 0; i < params.length; i++) { String key = params[i][0]; String value = params[i][1];

if (value != null) { try { p += key + "=" + URLEncoder.encode(value, "UTF-8") + "&"; } catch (UnsupportedEncodingException ex) { Logger.getLogger(RestConnection.class.getName()).log(Level.SEVERE, null, ex); } }
SVTH : Tr Page 13

Bo co th c t p nh n th c Duy
} if (p.length() > 0) { p = p.substring(0, p.length() - 1); } } return p; }

GVHD : Tr nh Cng

private void setHeaders(String[][] headers) { if (headers != null) { for (int i = 0; i < headers.length; i++) { conn.setRequestProperty(headers[i][0], headers[i][1]); } } } }

+ T o l p RestResponse:
package org.netbeans.saas;

import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream;

SVTH : Tr

Page 14

Bo co th c t p nh n th c Duy
import java.io.StringReader; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.transform.stream.StreamSource;

GVHD : Tr nh Cng

public class RestResponse { private ByteArrayOutputStream os; private String contentType = "text/plain"; private String contentEncoding; private int responseCode; private String responseMsg; private long lastModified; public RestResponse() { os = new ByteArrayOutputStream(); } public RestResponse(byte[] bytes) throws IOException { this(); byte[] buffer = new byte[1024];

SVTH : Tr

Page 15

Bo co th c t p nh n th c Duy
int count = 0;

GVHD : Tr nh Cng

ByteArrayInputStream bis = new ByteArrayInputStream(bytes); while ((count = bis.read(buffer)) != -1) { write(buffer, 0, count); } } public void setContentType(String contentType) { this.contentType = contentType; } public String getContentType() { return contentType; } public void setContentEncoding(String contentEncoding) { this.contentEncoding = contentEncoding; } public void setResponseMessage(String msg) { this.responseMsg = msg; } public String getResponseMessage() { return responseMsg; } public void setResponseCode(int code) { this.responseCode = code;

SVTH : Tr

Page 16

Bo co th c t p nh n th c Duy
} public int getResponseCode() { return responseCode; } public void setLastModified(long lastModified) { this.lastModified = lastModified; } public long getLastModified() { return lastModified; } public void write(byte[] bytes, int start, int length) { os.write(bytes, start, length); } public byte[] getDataAsByteArray() { return os.toByteArray(); } public String getDataAsString() { try { return os.toString("UTF-8"); } catch (Exception ex) {

GVHD : Tr nh Cng

Logger.getLogger(RestConnection.class.getName()).log(Level.SEVERE, null, ex); } return null;

SVTH : Tr

Page 17

Bo co th c t p nh n th c Duy
} public OutputStream getOutputStream() { return os; }

GVHD : Tr nh Cng

public <T> T getDataAsObject(Class<T> jaxbClass) throws JAXBException { return getDataAsObject(jaxbClass, jaxbClass.getPackage().getName()); } public <T> T getDataAsObject(Class<T> clazz, String packageName) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(packageName); Unmarshaller u = jc.createUnmarshaller(); Object obj = u.unmarshal(new StreamSource(new StringReader(getDataAsString())));

if (obj instanceof JAXBElement) { return (T) ((JAXBElement) obj).getValue(); } else { return (T) obj; } } }

b. Xy d ng gi org.netbeans.saas.google : + T o l p GoogleMapService:
package org.netbeans.saas.google;

SVTH : Tr

Page 18

Bo co th c t p nh n th c Duy
import java.io.IOException; import java.net.URLEncoder; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.saas.RestConnection; import org.netbeans.saas.RestResponse; public class GoogleMapService {

GVHD : Tr nh Cng

private static String apiKey; private static final String PROP_FILE = GoogleMapService.class.getSimpleName().toLowerCase() + ".properties"; static { try { Properties props = new Properties(); props.load(GoogleMapService.class.getResourceAsStream(PROP_FILE)); apiKey = props.getProperty("api_key"); } catch (IOException ex) { Logger.getLogger(GoogleMapService.class.getName()).log(Level.SEVERE, null, ex); } } public static String getApiKey() throws IOException { if (apiKey == null || apiKey.length() == 0) {

SVTH : Tr

Page 19

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

throw new IOException("Please specify your api key in the " + PROP_FILE + " file."); } return apiKey; } public static RestResponse getGoogleMap(String address, Integer zoom, String iframe) throws IOException { try { String key = getApiKey(); String encoded = URLEncoder.encode(address, "UTF-8"); GeoCoder coder = new GeoCoder(encoded, apiKey); GeoCode code = coder.invoke(); String mapRep = ""; if(iframe != null && iframe.trim().equalsIgnoreCase("true")) { mapRep += " <div id='map' style='width: 800px; height: 500px'></div>\n"+ getMapScript(address, zoom, code.getLatitude(), code.getLongitude(), key)+ " <script type='text/javascript'>\n"+ " loadScript();\n"+

" </script>\n"; } else { mapRep = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'\n"+ " 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n"+
SVTH : Tr Page 20

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

"<html xmlns='http://www.w3.org/1999/xhtml'>\n"+ " <head>\n"+ " <meta http-equiv='content-type' content='text/html; charset=utf-8'/>\n"+ " <title>Google Maps JavaScript API Example</title>\n"+ getMapScript(address, zoom, code.getLatitude(), code.getLongitude(), key)+ " </head>\n"+ " <body onload='loadScript()' onunload='GUnload()'>\n"+ " <div id='map' style='width: 500px; height: 300px'></div>\n"+ " </body>\n"+ "</html>"; } return new RestResponse(mapRep.getBytes()); } catch (Exception ex) { throw new IOException(ex.getMessage()); } }

public static String getMapScript(String address, Integer zoom, double latitude, double longitude, String key) { String mapRep = " <script type='text/javascript'>\n"+ " //<![CDATA[\n"+ " function loadMap() {\n"+

SVTH : Tr

Page 21

Bo co th c t p nh n th c Duy
" " " " " " " " " " if (GBrowserIsCompatible()) {\n"+

GVHD : Tr nh Cng

var map = new GMap2(document.getElementById('map'));\n"+ var point = new GLatLng("+latitude+", "+longitude+");\n"+ map.addControl(new GSmallMapControl());\n"+ map.addControl(new GMapTypeControl());\n"+ map.setCenter(point, " + zoom + ");\n"+ var marker = createMarker(point);\n"+ map.addOverlay(marker);\n"+ marker.openInfoWindowHtml(\"" + address + "\");\n"+ }\n"+

" }\n"+ " function createMarker(point) {\n" + " " " " " var marker = new GMarker(point);\n"+ GEvent.addListener(marker, \"click\", function() {\n"+ marker.openInfoWindowHtml(\"" + address + "\");\n"+ });\n"+ return marker;\n"+

" }\n"+ " function loadScript() {\n"+ " var script = document.createElement(\"script\");\n"+

" script.setAttribute(\"src\", \"http://maps.google.com/maps?file=api&v=2.x&key="+key+"&async=2&callback=loadM ap\");\n"+ "


SVTH : Tr

script.setAttribute(\"type\", \"text/javascript\");\n"+
Page 22

Bo co th c t p nh n th c Duy
"

GVHD : Tr nh Cng

document.documentElement.firstChild.appendChild(script);\n"+

" }\n"+ " //]]>\n"+ " </script>\n"; return mapRep; } public static class GeoCoder { public final static String GEOCODE_URL = "http://maps.google.com/maps/geo"; private String location; private String key;

/** Creates a new instance of GeoCoder */ public GeoCoder(String location, String key) { this.location = location; this.key = key; } public GeoCode invoke() throws IOException { String[][] params = new String[][] { {"q", location}, {"output", "xml"}, {"key", key} }; RestConnection cl = new RestConnection(GEOCODE_URL, params);

SVTH : Tr

Page 23

Bo co th c t p nh n th c Duy
RestResponse response = cl.get(); String codeStr = response.getDataAsString(); return new GeoCode(codeStr); } } public static class GeoCode { private double longitude ; private double latitude;

GVHD : Tr nh Cng

/** Creates a new instance of GeoCode */ public GeoCode(String xmlStr) { int ts = xmlStr.indexOf("<coordinates>"); int te = xmlStr.indexOf("</coordinates>"); String codeStr = ""; if(ts != -1 && te != -1) codeStr = xmlStr.substring(ts+13, te); String[] codes = codeStr.split(","); if(codes.length>1) { this.longitude = Double.parseDouble(codes[0]); this.latitude = Double.parseDouble(codes[1]); } } public double getLongitude() {

SVTH : Tr

Page 24

Bo co th c t p nh n th c Duy
return this.longitude; } public double getLatitude() { return this.latitude; } } }

GVHD : Tr nh Cng

+ T o property googlemapservice: c. T o file index.jsp :


<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>View the Googlemap Demo</title> </head> <body> <h1>Google map API service!</h1> <form action="index.jsp"> Address: <input name="address"> <input type="submit" value="GO">
SVTH : Tr Page 25

Bo co th c t p nh n th c Duy
</form>

GVHD : Tr nh Cng

<%@ page import="org.netbeans.saas.*, org.netbeans.saas.google.*" %> <% try { String address = request.getParameter("address"); java.lang.Integer zoom = 10; String iframe = "true"; RestResponse result = GoogleMapService.getGoogleMap(address, zoom, iframe); //TODO - Uncomment the print Statement below to print result. out.println("The MAP SaasService returned: "+result.getDataAsString()); } catch (Exception ex) { ex.printStackTrace(); } %> </body> </html>

V.

ng d ng minh h a :

SVTH : Tr

Page 26

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

SVTH : Tr

Page 27

Bo co th c t p nh n th c Duy

GVHD : Tr nh Cng

VI.

Ph l c tham kh o :

Googlemapservice class: http://code.google.com/p/tripnetworkingsite/source/browse/trunk/AwesomeTrips/src/java /org/netbeans/saas/google/GoogleMapService.java?r=39


RestConnection class: http://49ers.es/welcomehome/javadoc/org/netbeans/saas/RestConnection.html

http://code.google.com/p/personalcloudsyncfr/source/browse/DocumentWatcher/src/org/ netbeans/saas/RestConnection.java?r=295 RestResponse class: http://49ers.es/welcomehome/javadoc/org/netbeans/saas/RestResponse.html http://code.google.com/p/tripnetworkingsite/source/browse/trunk/AwesomeTrips/src/java /org/netbeans/saas/RestResponse.java?r=39 api_key: ABQIAAAAT3oDobl9bEVE3K2BOBXEBQg2HBMA_uLzZJtX4XkuiGzyMfk8BSm5ir6AShkWVFZI r21ZfDsiTR6Pg

SVTH : Tr

Page 28

You might also like