【Salesforce】地理位置情報項目を使って周辺検索 GMaps
參考
https://upward.jp/weblog/howtousegeolocation/
https://developer.salesforce.com/forums/?id=906F0000000AnNsIAKhttp://tyoshikawa1106.hatenablog.com/entry/2013/06/05/014128
https://developer.salesforce.com/docs/atlas.ja-jp.202.0.pages.meta/pages/pages_maps.htm
http://www.terrasky.co.jp/blog/2015/150212_001401.php
https://www.synergy-marketing.co.jp/cloud/synergylead/support/faq-salesforce-google-maps/
https://developer.salesforce.com/docs/atlas.ja-jp.202.0.apexcode.meta/apexcode/apex_class_system_Address.htm
http://blogjp.sforce.com/2011/01/google-maps-jav.html
https://code-de.co/google-maps-api-multi-markers/
http://skyblues.org/arts/2777
http://www.runoob.com/googleapi/googleapi-tutorial.html
住所やランドマーク名から経度、緯度を検索
http://www.geocoding.jp/
google map 中marker圖標集合
http://www.verydemo.com/demo_c407_i2585.html
サンプル
VisualForce
<apex:page standardController="Account" extensions="GoogleMapCtrl"> <head> <script type="text/javascript" src="//maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript" src="https://hpneo.github.io/gmaps/gmaps.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript"> var map; $(document).ready(function(){createMap(); });function createMap(){map = new GMaps({div: "#map-02",lat: "{!Account.BillingLatitude}",lng: "{!Account.BillingLongitude}",zoom: 11}); var marks = {!jsonStr};for (var i in marks) {addMarker(map,marks[i]);} // 対象住所map.addMarker({lat: "{!Account.BillingLatitude}",lng: "{!Account.BillingLongitude}",icon: "{!$Resource.marker_green}",title: "{!Account.Name}",infoWindow: {content: "{!Account.BillingState}{!Account.BillingCity}{!Account.BillingStreet}"}}); }function addMarker( map,mark){map.addMarker({lat: mark.lat,lng: mark.lng,title: mark.title,infoWindow: {content: mark.content}}); }</script> </head> <apex:form id="frm"><apex:pageBlock > <apex:outputpanel ><apex:pageBlockSection ><apex:pageBlockSectionItem ><div class="gmaps"><div id="map-02" style="width: 990px;height: 400px"></div></div></apex:pageBlockSectionItem> </apex:pageBlockSection><apex:pageBlockSection ><apex:pageBlockSectionItem labelStyle="text-align:left"><apex:outputpanel > <apex:commandButton action="{!doZoomPuls}" value="+" id="pulsButton" style="width:40px; font-weight:bold" /><apex:commandButton action="{!doZoomMinus}" value="-" id="minusButton" style="width:40px;font-weight:bold"/><apex:outputText value="検索範囲: " /><apex:inputText id="dist" value="{!findDistance}" style="width:40px;" /><apex:outputText value=" (km)" /><apex:commandButton action="{!getMapsInfos}" value="検索" id="searchBtn" style="width:40px;"/></apex:outputpanel></apex:pageBlockSectionItem></apex:pageBlockSection> </apex:outputpanel><apex:outputpanel > <apex:pageBlockSection ><apex:pageBlockSectionItem ><apex:pageBlockTable value="{!mapDtoList}" var="rec"><apex:column Style="width:700px"><apex:facet name="header">隣接住所</apex:facet><apex:outputlink value="/{!rec.id}" target="_blank"><apex:outputLabel value="{!rec.content}"/></apex:outputlink></apex:column><apex:column Style="width:100px"><apex:facet name="header">距離(km)</apex:facet><apex:outputText value="{!rec.calcDist}"/> </apex:column></apex:pageBlockTable></apex:pageBlockSectionItem></apex:pageBlockSection></apex:outputpanel></apex:pageBlock> </apex:form> </apex:page>Apex public class GoogleMapCtrl {public Account acc;// 検索範囲public decimal findDistance {get;set;}public decimal zoom {get;set;}public string jsonStr {get;set;}public list<mapDto> mapDtoList {get; set;}public GoogleMapCtrl(ApexPages.StandardController controller) { if(findDistance == null){this.findDistance = 10;}if(zoom == null){zoom = 12;} list<string> field = new list<string>();field.add('BillingLatitude');field.add('BillingLongitude');controller.addFields(field);this.acc = (Account)controller.getRecord();getMapsInfos(); }/**マップ情報を取得*/public PageReference getMapsInfos(){system.debug('========findDistance==========='+findDistance);decimal lat = acc.BillingLatitude;decimal lng = acc.BillingLongitude;string query = ''; query = 'SELECT ';query += 'id';query += ',Name';query += ',BillingLatitude';query += ',BillingLongitude';query += ',BillingStreet';query += ',BillingPostalCode';query += ',BillingCity';query += ',BillingState';query += ',BillingCountry';query += ',BillingAddress';query += ',DISTANCE( BillingAddress, GEOLOCATION('+lat+','+lng+'), '+ '\'' +'km' +'\'' +') DIC ';query += 'FROM ';query += 'Account ';query += 'WHERE ';query += 'DISTANCE( BillingAddress, GEOLOCATION('+lat+','+lng+'), '+ '\'' +'km' + '\''+') <' + string.valueof(findDistance);query += ' and BillingLongitude !=null and BillingLatitude != null and BillingState !=null';query += ' and id !=' + '\'' + acc.id +'\'';query += ' Order by ';query += ' Distance(BillingAddress, GEOLOCATION('+lat +',' + lng +'),' + '\''+'km'+'\''+')';system.debug('======query========'+query);List<Account> nearAccountList = DataBase.query(query); /*List<Account> nearAccountList = [SELECT id,Name,BillingLatitude,BillingLongitude,BillingStreet,BillingPostalCode,BillingCity,BillingState,BillingCountry ,BillingAddress,DISTANCE( BillingAddress, GEOLOCATION(:lat, :lng), 'km' ) DICFROM AccountWHERE Distance(BillingAddress, GEOLOCATION(:lat, :lng), 'km') < :findDistanceand BillingLongitude !=null and BillingLatitude != null and BillingState !=nulland id != :acc.idOrder by Distance(BillingAddress, GEOLOCATION(:lat, :lng), 'km')]; */ this.mapDtoList = new list<mapDto>();for(Account item : nearAccountList){mapDto dto = new mapDto();dto.id = item.id;dto.title = item.Name;dto.lat = item.BillingLatitude;dto.lng = item.BillingLongitude;dto.BillingState = item.BillingState;dto.BillingCity = item.BillingCity;dto.BillingStreet = item.BillingStreet;dto.content = dto.getContent();dto.calcDist = roundNumber((decimal)item.get('DIC' ),2);this.mapDtoList.add(dto); }this.jsonStr = JSON.serialize(this.mapDtoList); system.debug('======jsonStr========'+jsonStr); return null; }public void doZoomPuls(){this.findDistance +=0.5;getMapsInfos();}public void doZoomMinus(){this.findDistance -=0.5;getMapsInfos();} public class mapDto{public String title {get;set;}public String content {get;set;}public decimal lat {get;set;}public decimal lng {get;set;}public decimal calcDist {get;set;}public string BillingState {get;set;} public string BillingCity {get;set;}public string BillingStreet {get;set;}public string id {get;set;}public mapDto(){this.id ='';this.title = '';this.content = '';this.lat = 0;this.lng = 0;this.BillingState = '';this.BillingCity = '';this.BillingStreet = '';this.calcDist =0;}public string getContent(){return this.content = this.BillingState + this.BillingCity + this.BillingStreet;}}//四捨五入public Decimal roundNumber(Decimal roundNumber , Integer decimalPlace) { if(roundNumber != null) {return roundNumber.setScale(decimalPlace, RoundingMode.HALF_UP);} else { return 0 ; } }}
總結
以上是生活随笔為你收集整理的【Salesforce】地理位置情報項目を使って周辺検索 GMaps的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【MySQL】MySQL之导入和导出
- 下一篇: 手机rom制作,我们应该知道的那些事